Commit acec36d8 authored by Pekka Pessi's avatar Pekka Pessi

su_wait.c: put socket in non-blocking mode when wait object is created

darcs-hash:20061016134418-65a35-1a07aca944279bda5284c01d560b678ebd348a7d.gz
parent 79ed9491
...@@ -113,6 +113,13 @@ void su_wait_init(su_wait_t dst[1]) ...@@ -113,6 +113,13 @@ void su_wait_init(su_wait_t dst[1])
* The function su_wait_create() creates a new su_wait_t object for an @a * The function su_wait_create() creates a new su_wait_t object for an @a
* socket, with given @a events. The new wait object is assigned to the @a * socket, with given @a events. The new wait object is assigned to the @a
* newwait parameter. * newwait parameter.
*
* There can be only one wait object per socket. (This is a limitation or
* feature of WinSock interface; the limitation is not enforced on other
* platforms).
*
* As a side-effect the socket is put into non-blocking mode when wait
* object is created.
* *
* @param newwait the newly created wait object (output) * @param newwait the newly created wait object (output)
* @param socket socket * @param socket socket
...@@ -143,12 +150,20 @@ int su_wait_create(su_wait_t *newwait, su_socket_t socket, int events) ...@@ -143,12 +150,20 @@ int su_wait_create(su_wait_t *newwait, su_socket_t socket, int events)
*newwait = h; *newwait = h;
#elif SU_HAVE_POLL #elif SU_HAVE_POLL
int mode;
if (newwait == NULL || events == 0 || socket == INVALID_SOCKET) { if (newwait == NULL || events == 0 || socket == INVALID_SOCKET) {
su_seterrno(EINVAL); su_seterrno(EINVAL);
return -1; return -1;
} }
mode = fcntl(socket, F_GETFL, 0);
if (mode < 0)
return -1;
mode |= O_NDELAY | O_NONBLOCK;
if (fcntl(socket, F_SETFL, mode) < 0)
return -1;
newwait->fd = socket; newwait->fd = socket;
newwait->events = events; newwait->events = events;
newwait->revents = 0; newwait->revents = 0;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment