From 635debdd1d9f4b4982cdff91fcb244b64ea341fc Mon Sep 17 00:00:00 2001 From: Sebastian Harl Date: Fri, 25 Oct 2013 18:57:28 +0200 Subject: [PATCH] socket frontend: Use nonblocking I/O for open connections. --- src/frontend/sock.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) 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 */ -- 2.30.2