From: Sebastian Harl Date: Fri, 25 Oct 2013 16:57:28 +0000 (+0200) Subject: socket frontend: Use nonblocking I/O for open connections. X-Git-Tag: sysdb-0.1.0~336^2~35 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=635debdd1d9f4b4982cdff91fcb244b64ea341fc;p=sysdb.git socket frontend: Use nonblocking I/O for open connections. --- diff --git a/src/frontend/sock.c b/src/frontend/sock.c index 3662a26..a389a14 100644 --- a/src/frontend/sock.c +++ b/src/frontend/sock.c @@ -43,6 +43,8 @@ #include +#include + #include #include #include @@ -235,6 +237,7 @@ connection_init(sdb_object_t *obj, va_list ap) { connection_t *conn; int sock_fd; + int sock_fl; assert(obj); conn = &CONN(obj)->conn; @@ -259,7 +262,16 @@ connection_init(sdb_object_t *obj, va_list ap) return -1; } - sdb_log(SDB_LOG_DEBUG, "frontend: Accepted connection on fd=%i\n", + sock_fl = fcntl(conn->fd, F_GETFL); + if (fcntl(conn->fd, F_SETFL, sock_fl | O_NONBLOCK)) { + char buf[1024]; + sdb_log(SDB_LOG_ERR, "frontend: Failed to switch connection conn#%i " + "to non-blocking mode: %s", conn->fd, + sdb_strerror(errno, buf, sizeof(buf))); + return -1; + } + + sdb_log(SDB_LOG_DEBUG, "frontend: Accepted connection on fd=%i", conn->fd); /* update the object name */