Commit 4730cd31 authored by Ziye Yang's avatar Ziye Yang Committed by Ben Walker
Browse files

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: default avatarZiye Yang <ziye.yang@intel.com>
Reviewed-on: https://review.gerrithub.io/428654


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Chandler-Test-Pool: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: default avatarGangCao <gang.cao@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
parent 1f6a7862
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -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");