diff --git a/lib/sock/posix/posix.c b/lib/sock/posix/posix.c index fc341f06a..565d38926 100644 --- a/lib/sock/posix/posix.c +++ b/lib/sock/posix/posix.c @@ -319,6 +319,7 @@ spdk_posix_sock_accept(struct spdk_sock *_sock) socklen_t salen; int rc; struct spdk_posix_sock *new_sock; + int flag; memset(&sa, 0, sizeof(sa)); salen = sizeof(sa); @@ -331,6 +332,13 @@ spdk_posix_sock_accept(struct spdk_sock *_sock) return NULL; } + flag = fcntl(rc, F_GETFL); + if ((!(flag & O_NONBLOCK)) && (fcntl(rc, F_SETFL, flag | O_NONBLOCK) < 0)) { + SPDK_ERRLOG("fcntl can't set nonblocking mode for socket, fd: %d (%d)\n", rc, errno); + close(rc); + return NULL; + } + new_sock = calloc(1, sizeof(*sock)); if (new_sock == NULL) { SPDK_ERRLOG("sock allocation failed\n");