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 <ziye.yang@intel.com>
Reviewed-on: https://review.gerrithub.io/428654
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Chandler-Test-Pool: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: GangCao <gang.cao@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
Ziye Yang 2018-10-11 03:49:55 +08:00 committed by Ben Walker
parent 1f6a78620d
commit 4730cd3158

View File

@ -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");