AIX

AIX

Connect with fellow AIX users and experts to gain knowledge, share insights, and solve problems.


#Power
 View Only
  • 1.  AIX socket programming very strange behavioyr

    Posted Mon May 10, 2010 02:37 PM

    Originally posted by: kumar_m_kiran


    Below behavior is a strange behavior which we are observing in the production code. As with socket based programming, we have client/server set-up. Below is the behavior of the code at server side (code snippet).

    Pseudo Code
    CSocket::processMsg()
    {
    while(dataSize != PackateSize)
    {
    lreadStatus = ::recv(...);
    //Above code to read specific block of data is present.
    lerror = errno; //save the errono details.
    if(lreadStatus < 0 ) //Error while reading
    {
    //Flag an error and return
    // Return unable to read
    return error;
    }
    retry = 0;

    if(lreadStatus == 0)
    {
    if( retry == MAX_RETRY)
    {
    return errorMaxRetry;
    }

    retry++;
    lpingStatus = ::send("Alive");
    if(EPIPE == lpingStatus)
    {
    return error;
    }
    }
    dataSize += lreadStatus;

    } //end while
    } //end processMsg

    Idea behind the code
    1. Execute recv (system call for socket reading), till all the package size is read.
    2. If the recv return value is less than 0, then return (value read in that socket is invalid).
    3. If the recv return value is 0, may be some delay in read - do step 4.
    4. Since 0 bytes are read, send a ping message - if it is successful, socket is working properly go to step 3, else if SIGPIPE (EPIPE) is found, then return from the function.

    Problem Faced/Questions
    Question 1.a. In AIX platform, at production site, the recv return value is 0 (i.e no bytes are read), however the send data is successful. I am very sure that the client is send data to the server continuously. This is leading to some kind of repeated looping every time.

    1.b.Is there any scenario where the data (sent from another entity continuously) when read, reads 0 bytes from the socket. However sending the 'ping' data will successful?

    Question 2.a If the read socket provides 0 (zero), then the above logic is based on the approach that till a ping is deliverable in the socket (without EPIPE), the state of the socket is perfect and readable. Is this assumption correct?

    2.b.Is the socket implementation half-duplex? where send can be successful but recv can provide a 0 bytes read?

    Other Information
    1. Code is written in C++ base.
    2. Code works perfectly fine in SUSE10/HP-UX 11.1 OS.
    3. We are using AIX 5.3 version for release.
    4. Specific Socket Options - timed Wait socket (wait period 5 secs), SO_LINGER ON (time 5 secs).

    Thanks in advance for your input.
    #AIX-Forum


  • 2.  Re: AIX socket programming very strange behavioyr

    Posted Mon May 10, 2010 02:40 PM

    Originally posted by: kumar_m_kiran


    Two more points to be updated
    1. All signal handling is done in the production code.
    2. I am aware that recv(2) will return 0 in case of orderly shutdown of the sending entity. That is one of the reasons to claim "Strange" and "Working perfectly in SUSE/HP".
    #AIX-Forum


  • 3.  Re: AIX socket programming very strange behavioyr

    Posted Tue May 11, 2010 07:59 AM

    Originally posted by: MarkTaylor


    You might want to post that question here http://www.ibm.com/developerworks/forums/forum.jspa?forumID=905 or here http://www.ibm.com/developerworks/forums/forum.jspa?forumID=1333

    Rgds
    Mark Taylor
    #AIX-Forum