Problem With Non Blocking connect and select - HP UX

This is a discussion on Problem With Non Blocking connect and select - HP UX ; Hi I have written the following client code on HUPX for connecting to a server in NONBLOCKING mode. After that if errorno is EINPROGRESS I am using select to check whether socket is ready to write. The issue I am ...

+ Reply to Thread
Results 1 to 2 of 2

Thread: Problem With Non Blocking connect and select

  1. Problem With Non Blocking connect and select

    Hi
    I have written the following client code on HUPX for connecting to
    a server in NONBLOCKING mode. After that if errorno is EINPROGRESS I
    am using select to check whether socket is ready to write. The issue I
    am facing is, the return value of FD_ISSET is a non zero value even if
    my server is not running. This issue is there only when my server IP
    points to a HPUX m/c. If server points to a windows m/c then this code
    works properly. Can anybody please help me why is this behaviour

    #include
    #include
    #include
    #include
    #include
    #include
    #include
    #include
    #include
    #include
    #include

    int main() {
    int SockD;
    struct sockaddr_in DestAddr;
    int ConnID;
    long arg;

    // Create socket
    if(( SockD = socket(AF_INET, SOCK_STREAM, 0))< 0) {
    fprintf(stderr, "Error creating socket (%d %s)\n", errno,
    strerror(errno));
    return -1;
    }
    else
    cout<<"successfull connection"<
    // Set non-blocking
    arg = fcntl(SockD, F_GETFL, NULL);
    // arg &= ~O_NONBLOCK;
    arg |= O_NONBLOCK;
    fcntl(SockD, F_SETFL, arg);

    memset(&DestAddr, 0 , sizeof(DestAddr));
    DestAddr.sin_family = AF_INET;
    DestAddr.sin_port = htons(7099);
    DestAddr.sin_addr.s_addr = inet_addr("16.167.10.37");

    if ((ConnID = connect(SockD, (struct sockaddr *)&DestAddr, sizeof
    (DestAddr))) < 0) {
    if(errno == EINPROGRESS) {
    cout<<" EINPROGRESS 1\n"<
    fd_set fdvarp;
    FD_ZERO(&fdvarp);
    FD_CLR(SockD,&fdvarp);
    FD_SET(SockD,&fdvarp);
    timeval timeOut1;
    timeOut1.tv_sec = 1*60;
    timeOut1.tv_usec = 0;

    errno = 0;
    int RetVal = select ((SockD + 1), NULL,&fdvarp ,NULL ,&timeOut1);

    cout<<"RetVal Error errno =" < if((FD_ISSET(SockD,&fdvarp) == 0)) {
    cout<<" EINPROGRESS2 Not Connected.....Exiting \n"< return 1;
    }

    //DBGOBJ.Print("VikSockMgr.C :: Inside SockWrite DataP = %p, NBytes
    = %d\n", DataP, NBytes);
    int nwritten = write(SockD,"ANITHA", 6);

    if (nwritten < 0) {
    return (nwritten);
    }
    }
    cout<<"Return from connect"< return 0;
    }
    cout<<"Connect failed"< return 0;
    }


  2. Re: Problem With Non Blocking connect and select

    While the HP-UX 11.11 manpage could be a bit more verbose on the
    topic, select() will return for that EINPROGRESS connecting socket
    when _anything_ happens on the socket. It could be when the
    connection completes, it could be when the connection attempt fails.

    When speaking to a system on which there is not corresponding server
    with a listen endpoint, generally a TCP RST segment will be emitted,
    which should cause the "connect" to fail which means the select needs
    to complete and so you know to check the socket it must report a
    non-zero in the fd_set. If there is a firewall or something that is
    causing the SYN to be completely ignored, or the RST coming back to be
    filtered, then you will stay in the select() call until the timeout -
    either the one you use in select(), or the connection establishment
    timeout (tcp_ip_abort_cinterval IIRC).

    So, unless I've misunderstood something, your code may indeed be
    behaving correctly in both cases. Taking a packet trace with the
    likes of tcpdump watching traffic with that port number could probably
    help confirm what I'm saying.

    rick jones
    --
    web2.0 n, the dot.com reunion tour...
    these opinions are mine, all mine; HP might not want them anyway...
    feel free to post, OR email to rick.jones2 in hp.com but NOT BOTH...

+ Reply to Thread