From 4730cd315840894e9c003a45636aadb6331d6b36 Mon Sep 17 00:00:00 2001 From: Ziye Yang Date: Thu, 11 Oct 2018 03:49:55 +0800 Subject: [PATCH] sock: set the fd with non_block flag. Reason: For connect, we use non_block mode in the initiator side, but we do not do it for the accepted fd in the server side, which will casue writev not return. And this patch can fix this. PS: SPDK default use non block mode. Change-Id: I709574573a089c2e63ca079829945e864d9f20c2 Signed-off-by: Ziye Yang Reviewed-on: https://review.gerrithub.io/428654 Tested-by: SPDK CI Jenkins Chandler-Test-Pool: SPDK Automated Test System Reviewed-by: GangCao Reviewed-by: Jim Harris Reviewed-by: Ben Walker --- lib/sock/posix/posix.c | 8 ++++++++ 1 file changed, 8 insertions(+) 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");