Re: Trying to learn Non-Blocking sockets on Solaris 8, please help! ready to fork() it.

From: David Schwartz (davids_at_webmaster.com)
Date: 05/27/03

  • Next message: Marc Rochkind: "Re: Trying to learn Non-Blocking sockets on Solaris 8, please help! ready to fork() it."
    Date: Mon, 26 May 2003 16:57:09 -0700
    
    

    "Chris Ritchey" <rethnor@yahoo.com> wrote in message
    news:480de79d.0305261126.574c0bce@posting.google.com...
    > ok I've tried for the last two days to get some good information on
    > how to setup a non-blocking socket. I've found limited information on
    > fcntl and ioctl, but no secure meat on the matter. I have tried just
    > opening a socket and using the ioctl(...) to set it to non-blocking
    > however the compiler (gcc and CC) both complain about the function
    > ioctl not having a prototype.
    >
    > /* set to non-blocking */
    > int dummy = 1;
    > if(ioctl(listenerSD, FIONBIO, (char *) &dummy) < 0)
    > {
    > cout << "non-blocking failed." << endl;
    > return 0;
    > }
    >
    > I am including <sys/ioctl.h> and all the necesary sockets libraries.
    > is there perhaps an option I need to pass to the compiler to link to a
    > library (-lsocket -lnfs or what ever).

        Use the following instead:

    fcntl(sock, F_SETFL, fcntl(sock, F_GETFL, 0) | O_NONBLOCK);

    > Next Question would be, once(if) I've established a non-blocking
    > socket how do I check if there are messages/connection, not sure what
    > to calls them, waiting to be handled. I'm starting to think that one
    > would use the read function, if so how does that work, does it it
    > retreive this from some kind of queue? and at some point I check if
    > there is anything in the queue then retreive it?

        You can use 'poll' or 'select', you can use '/dev/poll', or you can just
    call a function every 'once in a while' to see if it can complete without
    blocking. The 'read' function always reads data from the receive queue.

    > I've also read forking with blocking as an option. Not sure if this is
    > a viable solution but would it be similiar if you forked of a seperate
    > process with the listener socket and each time a connection was
    > accepted fork it off to yet another process so that the original
    > process could continue listening? if thats an option what be the
    > advantage of forking the program over using non-blocking sockets.

        How would you handle multiple connections with non-blocking sockets?

        DS


  • Next message: Marc Rochkind: "Re: Trying to learn Non-Blocking sockets on Solaris 8, please help! ready to fork() it."

    Relevant Pages