Don't just SETFL O_NONBLOCK, first GETFL.

This commit is contained in:
Emil Mikulic 2006-12-13 12:31:30 +00:00
parent b86889f027
commit f3ce5d1eb9
1 changed files with 8 additions and 3 deletions

View File

@ -458,10 +458,15 @@ static void appendf(struct apbuf *buf, const char *format, ...)
/* ---------------------------------------------------------------------------
* Make the specified socket non-blocking.
*/
static void nonblock_socket(const int sock)
static void
nonblock_socket(const int sock)
{
assert(sock != -1);
if (fcntl(sock, F_SETFL, O_NONBLOCK) == -1)
int flags = fcntl(sock, F_GETFL, NULL);
if (flags == -1)
err(1, "fcntl(F_GETFL)");
flags |= O_NONBLOCK;
if (fcntl(sock, F_SETFL, flags) == -1)
err(1, "fcntl() to set O_NONBLOCK");
}