Socket client problems - IBM AS400

This is a discussion on Socket client problems - IBM AS400 ; Hello everyone, I have a tcp/ip socket client on the AS/400 that connects to a server (the server is currently on the AS/400 for testing, but won't be in the future). The issue is that I'm trying to set up ...

+ Reply to Thread
Results 1 to 5 of 5

Thread: Socket client problems

  1. Socket client problems

    Hello everyone,

    I have a tcp/ip socket client on the AS/400 that connects to a server (the
    server is currently on the AS/400 for testing, but won't be in the future).

    The issue is that I'm trying to set up a delay when checking for data.
    Currently my sockets are blocking, which I prefer over non-blocking. The
    socket client has to be able to perform a 2 way communication. What it does
    is checks for data in a data queue, if no data, check for socket data coming
    in, and process. If no socket data, return to check the data queue again,
    etc. If there is data in the data queue, send it through the socket.

    Begsr srPollSocket;
    SocketHasData = *off;

    // Define timeout duration for Select()
    WaitSec = 1;

    p_oldtv = p_timeval;
    size = %size(timeval);

    /end-free
    C alloc size p_timeval
    /free

    // Clear all File Descriptors
    FD_ZERO(fdset);

    // Set File Descriptor ON for the socket
    FD_SET(sock:fdset);

    tv_sec = WaitSec;
    RetCode = Select(sock+1:%addr(fdset):*NULL:*NULL_timeval);
    dealloc p_timeval;

    p_timeval = p_oldtv;

    // If File Descriptor is ON, then data is in the socket
    //If FD_ISSET(sock:fdset) = *on and RetCode > 0;
    If FD_ISSET(sock:fdset) = *on;
    SocketHasData = *on;
    Endif;

    Endsr;

    The program works perfectly for the most part, but after running for a
    while, without getting data, FD_ISSET comes back true. When I check the
    RetCode (returned from the select) it's value is -1 which tells me that
    somehow it's not connected, but it is still connected to the server! The
    code above will set SocketHasData = *On which will cause the program to read
    the socket. But the program then freezes because there is no data there.

    Can anyone offer any advice?

    Thanks!
    Kent




  2. Re: Socket client problems

    il 05/09/2007 23.16, Scrive Kent Knapp 40647816:
    > Hello everyone,
    >
    > I have a tcp/ip socket client on the AS/400 that connects to a server (the
    > server is currently on the AS/400 for testing, but won't be in the future).
    >
    > The issue is that I'm trying to set up a delay when checking for data.
    > Currently my sockets are blocking, which I prefer over non-blocking. The
    > socket client has to be able to perform a 2 way communication. What it does
    > is checks for data in a data queue, if no data, check for socket data coming
    > in, and process. If no socket data, return to check the data queue again,
    > etc. If there is data in the data queue, send it through the socket.
    >
    > Begsr srPollSocket;
    > SocketHasData = *off;
    >
    > // Define timeout duration for Select()
    > WaitSec = 1;
    >
    > p_oldtv = p_timeval;
    > size = %size(timeval);
    >
    > /end-free
    > C alloc size p_timeval
    > /free
    >
    > // Clear all File Descriptors
    > FD_ZERO(fdset);
    >
    > // Set File Descriptor ON for the socket
    > FD_SET(sock:fdset);
    >
    > tv_sec = WaitSec;
    > RetCode = Select(sock+1:%addr(fdset):*NULL:*NULL_timeval);
    > dealloc p_timeval;
    >
    > p_timeval = p_oldtv;
    >
    > // If File Descriptor is ON, then data is in the socket
    > //If FD_ISSET(sock:fdset) = *on and RetCode > 0;
    > If FD_ISSET(sock:fdset) = *on;
    > SocketHasData = *on;
    > Endif;
    >
    > Endsr;
    >
    > The program works perfectly for the most part, but after running for a
    > while, without getting data, FD_ISSET comes back true. When I check the
    > RetCode (returned from the select) it's value is -1 which tells me that
    > somehow it's not connected, but it is still connected to the server! The
    > code above will set SocketHasData = *On which will cause the program to read
    > the socket. But the program then freezes because there is no data there.
    >
    > Can anyone offer any advice?

    select function, as most of C functions returning an integer rc, returns
    -1 for multiple fault conditions not only for connection faults. Before
    making misleading suppositions, I would check errno that will be set by
    select function returning -1.
    To check errn, you should cal __errno function just once to assign the
    pointer to an integer variable, set errno to 0, just to prevent trusting
    a previous not checked error condition, then check errno if rc=-1.
    My preference is not to use alloc rpg function to set pointers
    repeatedly, in your case you do not need to use alloc because you always
    know how much byte is timeval structure, I would code its pointer like this:
    D timevalds ds based(timeval_p)
    D tv_fields...
    D timeval s like(timeval_ds)
    c eval timeval_p = %addr(timeval)

    Each errno is mapped to a CPExxxx of QCPFMSG, where xxxx is the errno,
    that's always 4 digits.

    Example:

    D setErrno pr * extproc('__errno')
    D errno s 10i o based(errno_p)
    D msgid s 7a
    C eval errno_p = setErrno
    C eval errno = 0
    ....
    C if RetCode = -1
    C eval msgid = 'CPE' + %trim(%editc(errno:'Z'))
    .... msgid contains CPExxxx that describes the error condition
    C else
    .... do read socket
    C endif

    --
    Dr.Ugo Gagliardelli,Modena,ItalyCertifiedUindoscrasherAñe joAlcoolInside
    Spaccamaroni andate a cagare/Spammers not welcome/Spammers vão à merda
    Spamers iros a la mierda/Spamers allez vous faire foutre/Spammers loop
    schijten/Spammers macht Euch vom Acker/Spamerzy wypierdalac'

  3. Re: Socket client problems

    Thank you! I will give that a try.

    "Dr.UgoGagliardelli" wrote in message
    news:46dfa3a1$0$21211$5fc30a8@news.tiscali.it...
    > il 05/09/2007 23.16, Scrive Kent Knapp 40647816:
    >> Hello everyone,
    >>
    >> I have a tcp/ip socket client on the AS/400 that connects to a server
    >> (the
    >> server is currently on the AS/400 for testing, but won't be in the
    >> future).
    >>
    >> The issue is that I'm trying to set up a delay when checking for data.
    >> Currently my sockets are blocking, which I prefer over non-blocking. The
    >> socket client has to be able to perform a 2 way communication. What it
    >> does
    >> is checks for data in a data queue, if no data, check for socket data
    >> coming
    >> in, and process. If no socket data, return to check the data queue
    >> again,
    >> etc. If there is data in the data queue, send it through the socket.
    >>
    >> Begsr srPollSocket;
    >> SocketHasData = *off;
    >>
    >> // Define timeout duration for Select()
    >> WaitSec = 1;
    >>
    >> p_oldtv = p_timeval;
    >> size = %size(timeval);
    >>
    >> /end-free
    >> C alloc size p_timeval
    >> /free
    >>
    >> // Clear all File Descriptors
    >> FD_ZERO(fdset);
    >>
    >> // Set File Descriptor ON for the socket
    >> FD_SET(sock:fdset);
    >>
    >> tv_sec = WaitSec;
    >> RetCode = Select(sock+1:%addr(fdset):*NULL:*NULL_timeval);
    >> dealloc p_timeval;
    >>
    >> p_timeval = p_oldtv;
    >>
    >> // If File Descriptor is ON, then data is in the socket
    >> //If FD_ISSET(sock:fdset) = *on and RetCode > 0;
    >> If FD_ISSET(sock:fdset) = *on;
    >> SocketHasData = *on;
    >> Endif;
    >>
    >> Endsr;
    >>
    >> The program works perfectly for the most part, but after running for a
    >> while, without getting data, FD_ISSET comes back true. When I check the
    >> RetCode (returned from the select) it's value is -1 which tells me that
    >> somehow it's not connected, but it is still connected to the server! The
    >> code above will set SocketHasData = *On which will cause the program to
    >> read
    >> the socket. But the program then freezes because there is no data there.
    >>
    >> Can anyone offer any advice?

    > select function, as most of C functions returning an integer rc,
    > returns -1 for multiple fault conditions not only for connection faults.
    > Before making misleading suppositions, I would check errno that will be
    > set by select function returning -1.
    > To check errn, you should cal __errno function just once to assign the
    > pointer to an integer variable, set errno to 0, just to prevent trusting a
    > previous not checked error condition, then check errno if rc=-1.
    > My preference is not to use alloc rpg function to set pointers repeatedly,
    > in your case you do not need to use alloc because you always know how much
    > byte is timeval structure, I would code its pointer like this:
    > D timevalds ds based(timeval_p)
    > D tv_fields...
    > D timeval s like(timeval_ds)
    > c eval timeval_p = %addr(timeval)
    >
    > Each errno is mapped to a CPExxxx of QCPFMSG, where xxxx is the errno,
    > that's always 4 digits.
    >
    > Example:
    >
    > D setErrno pr * extproc('__errno')
    > D errno s 10i o based(errno_p)
    > D msgid s 7a
    > C eval errno_p = setErrno
    > C eval errno = 0
    > ...
    > C if RetCode = -1
    > C eval msgid = 'CPE' + %trim(%editc(errno:'Z'))
    > ... msgid contains CPExxxx that describes the error condition
    > C else
    > ... do read socket
    > C endif
    >
    > --
    > Dr.Ugo Gagliardelli,Modena,ItalyCertifiedUindoscrasherAñe joAlcoolInside
    > Spaccamaroni andate a cagare/Spammers not welcome/Spammers vão à merda
    > Spamers iros a la mierda/Spamers allez vous faire foutre/Spammers loop
    > schijten/Spammers macht Euch vom Acker/Spamerzy wypierdalac'





  4. Re: Socket client problems

    Thank you! I will give that a try.

    "Dr.UgoGagliardelli" wrote in message
    news:46dfa3a1$0$21211$5fc30a8@news.tiscali.it...
    > il 05/09/2007 23.16, Scrive Kent Knapp 40647816:
    >> Hello everyone,
    >>
    >> I have a tcp/ip socket client on the AS/400 that connects to a server
    >> (the
    >> server is currently on the AS/400 for testing, but won't be in the
    >> future).
    >>
    >> The issue is that I'm trying to set up a delay when checking for data.
    >> Currently my sockets are blocking, which I prefer over non-blocking. The
    >> socket client has to be able to perform a 2 way communication. What it
    >> does
    >> is checks for data in a data queue, if no data, check for socket data
    >> coming
    >> in, and process. If no socket data, return to check the data queue
    >> again,
    >> etc. If there is data in the data queue, send it through the socket.
    >>
    >> Begsr srPollSocket;
    >> SocketHasData = *off;
    >>
    >> // Define timeout duration for Select()
    >> WaitSec = 1;
    >>
    >> p_oldtv = p_timeval;
    >> size = %size(timeval);
    >>
    >> /end-free
    >> C alloc size p_timeval
    >> /free
    >>
    >> // Clear all File Descriptors
    >> FD_ZERO(fdset);
    >>
    >> // Set File Descriptor ON for the socket
    >> FD_SET(sock:fdset);
    >>
    >> tv_sec = WaitSec;
    >> RetCode = Select(sock+1:%addr(fdset):*NULL:*NULL_timeval);
    >> dealloc p_timeval;
    >>
    >> p_timeval = p_oldtv;
    >>
    >> // If File Descriptor is ON, then data is in the socket
    >> //If FD_ISSET(sock:fdset) = *on and RetCode > 0;
    >> If FD_ISSET(sock:fdset) = *on;
    >> SocketHasData = *on;
    >> Endif;
    >>
    >> Endsr;
    >>
    >> The program works perfectly for the most part, but after running for a
    >> while, without getting data, FD_ISSET comes back true. When I check the
    >> RetCode (returned from the select) it's value is -1 which tells me that
    >> somehow it's not connected, but it is still connected to the server! The
    >> code above will set SocketHasData = *On which will cause the program to
    >> read
    >> the socket. But the program then freezes because there is no data there.
    >>
    >> Can anyone offer any advice?

    > select function, as most of C functions returning an integer rc,
    > returns -1 for multiple fault conditions not only for connection faults.
    > Before making misleading suppositions, I would check errno that will be
    > set by select function returning -1.
    > To check errn, you should cal __errno function just once to assign the
    > pointer to an integer variable, set errno to 0, just to prevent trusting a
    > previous not checked error condition, then check errno if rc=-1.
    > My preference is not to use alloc rpg function to set pointers repeatedly,
    > in your case you do not need to use alloc because you always know how much
    > byte is timeval structure, I would code its pointer like this:
    > D timevalds ds based(timeval_p)
    > D tv_fields...
    > D timeval s like(timeval_ds)
    > c eval timeval_p = %addr(timeval)
    >
    > Each errno is mapped to a CPExxxx of QCPFMSG, where xxxx is the errno,
    > that's always 4 digits.
    >
    > Example:
    >
    > D setErrno pr * extproc('__errno')
    > D errno s 10i o based(errno_p)
    > D msgid s 7a
    > C eval errno_p = setErrno
    > C eval errno = 0
    > ...
    > C if RetCode = -1
    > C eval msgid = 'CPE' + %trim(%editc(errno:'Z'))
    > ... msgid contains CPExxxx that describes the error condition
    > C else
    > ... do read socket
    > C endif
    >
    > --
    > Dr.Ugo Gagliardelli,Modena,ItalyCertifiedUindoscrasherAñe joAlcoolInside
    > Spaccamaroni andate a cagare/Spammers not welcome/Spammers vão à merda
    > Spamers iros a la mierda/Spamers allez vous faire foutre/Spammers loop
    > schijten/Spammers macht Euch vom Acker/Spamerzy wypierdalac'




  5. Re: Socket client problems

    Just a quick follow up - your suggestion worked 100%. Thank you very much!


    "Dr.UgoGagliardelli" wrote in message
    news:46dfa3a1$0$21211$5fc30a8@news.tiscali.it...
    > il 05/09/2007 23.16, Scrive Kent Knapp 40647816:
    >> Hello everyone,
    >>
    >> I have a tcp/ip socket client on the AS/400 that connects to a server
    >> (the
    >> server is currently on the AS/400 for testing, but won't be in the
    >> future).
    >>
    >> The issue is that I'm trying to set up a delay when checking for data.
    >> Currently my sockets are blocking, which I prefer over non-blocking. The
    >> socket client has to be able to perform a 2 way communication. What it
    >> does
    >> is checks for data in a data queue, if no data, check for socket data
    >> coming
    >> in, and process. If no socket data, return to check the data queue
    >> again,
    >> etc. If there is data in the data queue, send it through the socket.
    >>
    >> Begsr srPollSocket;
    >> SocketHasData = *off;
    >>
    >> // Define timeout duration for Select()
    >> WaitSec = 1;
    >>
    >> p_oldtv = p_timeval;
    >> size = %size(timeval);
    >>
    >> /end-free
    >> C alloc size p_timeval
    >> /free
    >>
    >> // Clear all File Descriptors
    >> FD_ZERO(fdset);
    >>
    >> // Set File Descriptor ON for the socket
    >> FD_SET(sock:fdset);
    >>
    >> tv_sec = WaitSec;
    >> RetCode = Select(sock+1:%addr(fdset):*NULL:*NULL_timeval);
    >> dealloc p_timeval;
    >>
    >> p_timeval = p_oldtv;
    >>
    >> // If File Descriptor is ON, then data is in the socket
    >> //If FD_ISSET(sock:fdset) = *on and RetCode > 0;
    >> If FD_ISSET(sock:fdset) = *on;
    >> SocketHasData = *on;
    >> Endif;
    >>
    >> Endsr;
    >>
    >> The program works perfectly for the most part, but after running for a
    >> while, without getting data, FD_ISSET comes back true. When I check the
    >> RetCode (returned from the select) it's value is -1 which tells me that
    >> somehow it's not connected, but it is still connected to the server! The
    >> code above will set SocketHasData = *On which will cause the program to
    >> read
    >> the socket. But the program then freezes because there is no data there.
    >>
    >> Can anyone offer any advice?

    > select function, as most of C functions returning an integer rc,
    > returns -1 for multiple fault conditions not only for connection faults.
    > Before making misleading suppositions, I would check errno that will be
    > set by select function returning -1.
    > To check errn, you should cal __errno function just once to assign the
    > pointer to an integer variable, set errno to 0, just to prevent trusting a
    > previous not checked error condition, then check errno if rc=-1.
    > My preference is not to use alloc rpg function to set pointers repeatedly,
    > in your case you do not need to use alloc because you always know how much
    > byte is timeval structure, I would code its pointer like this:
    > D timevalds ds based(timeval_p)
    > D tv_fields...
    > D timeval s like(timeval_ds)
    > c eval timeval_p = %addr(timeval)
    >
    > Each errno is mapped to a CPExxxx of QCPFMSG, where xxxx is the errno,
    > that's always 4 digits.
    >
    > Example:
    >
    > D setErrno pr * extproc('__errno')
    > D errno s 10i o based(errno_p)
    > D msgid s 7a
    > C eval errno_p = setErrno
    > C eval errno = 0
    > ...
    > C if RetCode = -1
    > C eval msgid = 'CPE' + %trim(%editc(errno:'Z'))
    > ... msgid contains CPExxxx that describes the error condition
    > C else
    > ... do read socket
    > C endif
    >
    > --
    > Dr.Ugo Gagliardelli,Modena,ItalyCertifiedUindoscrasherAñe joAlcoolInside
    > Spaccamaroni andate a cagare/Spammers not welcome/Spammers vão à merda
    > Spamers iros a la mierda/Spamers allez vous faire foutre/Spammers loop
    > schijten/Spammers macht Euch vom Acker/Spamerzy wypierdalac'




+ Reply to Thread