[comp.unix.questions] non-blocking accept on sockets

ratuld@litp.UUCP (Jean DERATULD p4055) (07/26/88)

I would like to use sockets for communication between workstations.
A server process checks if there is a connection request from a client
with the "accept" function. The documentation on sockets says that there
is some flag to have a blocking or non-blocking "accept" on sockets
(the doc says about a SS_NBIO flag). The default is blocking sockets.
Nothing is said about how to set it locally,
the setsockopt function does not to seem to set it.
Is there a way to set non-blocking sockets?
Thanks for any info!
					Jean DeRatuld
USENET: litp!ratuld@inria.inria.fr.uucp

ron@topaz.rutgers.edu (Ron Natalie) (07/28/88)

The common way (and this is what inetd uses) is to use a select
on the file descriptor after the listen but before you actually
call accept to see if there is anything there to accept.

-Ron

chris@mimsy.UUCP (Chris Torek) (07/28/88)

In article <354@litp.UUCP> ratuld@litp.UUCP (Jean DERATULD p4055) writes:
>... The documentation on sockets says that there
>is some flag to have a blocking or non-blocking "accept" on sockets
>(the doc says about a SS_NBIO flag). The default is blocking sockets.
>Nothing is said about how to set it locally ....

The same way as any other non-blocking or no-delay I/O: either

	int on = 1, err;

	err = ioctl(fd, FIONBIO, &on);

or

	err = fcntl(fd, F_SETFL, FNDELAY);
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain:	chris@mimsy.umd.edu	Path:	uunet!mimsy!chris