hoff@en.ecn.purdue.edu (Michael Hoefflinger) (02/08/91)
We interrupt the regularly scheduled high-level UNIX(tm) conversation for this (seemingly) simple question: I'm using stream sockets to communicate between a client and a server process. In the server I use a call to accept() to connect to a client socket in the server's request queue. --> The question is how do I make this accept() call NON-BLOCKING? In other words, if there are no clients waiting to connect, I would like accept() to return with errno=EWOULDBLOCK instead of blocking until someone wants to connect. I've tried various attempts at setsockopt(), but nothing seems to do the trick. I guess I could set up a timer interval interrupt, but that seems cludgy (sp?) at best. I assure you any ideas would be VERY MUCH APPRECIATED... ADVthanksANCE Michael Hoefflinger "I'm not a EE grad student, but I play one on TV..." hoff@ei.ecn.purdue.edu (WYSE...) uxg@fugue.cc.purdue.edu (NeXT)
leh@atlantis.cis.ufl.edu (Les Hill) (02/09/91)
In article <1991Feb8.150520.5678@en.ecn.purdue.edu>, hoff@en.ecn.purdue.edu (Michael Hoefflinger) writes: |> --> The question is how do I make this accept() call NON-BLOCKING? In |> other words, if there are no clients waiting to connect, I would |> like accept() to return with errno=EWOULDBLOCK instead of blocking |> until someone wants to connect. |> Michael Hoefflinger |> uxg@fugue.cc.purdue.edu (NeXT) --> The answer is to use fcntl() (or perhaps ioctl() on your machine) and set the socket's descriptor to non-blocking. Under SunOS4.1.1 I would do either rc = fcntl(socket,F_SETFL,O_NDELAY); or rc = fcntl(socket,F_SETFL,FNDELAY); both of which will do the Right Thing (tm). Les Hill -- Extraordinary crimes against the people and the state have to be avenged by agents extraordinary. Two such people are John Steed -- top professional, and his partner, Emma Peel -- talented amateur; otherwise known as "The Avengers." UUCP: ...!gatech!uflorida!leh BITNET: vishnu@UFPINE INTERNET: leh@ufl.edu
mike_s@EBay.Sun.COM (Mike "Lakermaniac" Sullivan) (02/10/91)
In <26803@uflorida.cis.ufl.EDU> leh@atlantis.cis.ufl.edu (Les Hill) writes: >--> The answer is to use fcntl() (or perhaps ioctl() on your machine) and set > the socket's descriptor to non-blocking. Under SunOS4.1.1 I would do > either > rc = fcntl(socket,F_SETFL,O_NDELAY); > or > rc = fcntl(socket,F_SETFL,FNDELAY); > both of which will do the Right Thing (tm). Actually, while close to right, I believe the Right Thing is to first read the flags, then set FNDELAY in addition to the current flags. flags = fcntl(socket, F_GETFL, 0); fcntl(socket, F_SETFL, flags | FNDELAY); Mike -- Mike Sullivan Internet: msullivan@EBay.Sun.COM Sun Education UUCP: ..!sun!yavin!msullivan Software Course Developer Compuserve: 75365,764