Berkley sockets
Michael J. Hammel
mjhammel at Kepler.dell.com
Tue Mar 19 09:52:28 AEST 1991
In article <1991Mar14.193619.21766 at m.cs.uiuc.edu>, carroll at cs.uiuc.edu
(Alan M. Carroll) writes:
> A problem that I have had (2.0.2) with ISC is that if I have a socket
> that is a passive socket, and I poll() on it, waiting for input,
> poll() does _not_ return when another process connects to the socket
> (neither does select()).. This means that if I want to read/write on
> connected sockets _and_ listen for new connections, I lose.
Hmm. Maybe I don't understand the problem, but how about doing it like this:
for (;;) /* begin infinite loop waiting for new connections */
{
if ( (t=accept(s, &isa, &i) ) < 0) /* hang in accept, wait for new
connects*/
{
...error checking code
}
if ( (childpid=fork()) == 0) /* child process if fork() returns 0 */
{
...handle connection here in child process; the child inherits the socket
}
close(t); /* close the socket from the accept call */
}
This should allow you to read/write on connected sockets in a child
process and wait for more connections in the parent. You can specify
how many accepts can be queued with a listen() call, I believe. This
seems to work in a simple application I wrote.
Michael J. Hammel | mjhammel@{Kepler|socrates}.dell.com
Dell Computer Corp. | {73377.3467|76424.3024}@compuserve.com
#include <disclaim/std> | zzham at ttuvm1.bitnet | uunet!uudell!feynman!mjhammel
#define CUTESAYING "Recycle. Just do it."
More information about the Comp.unix.sysv386
mailing list