[ofa-general] ***SPAM*** [PATCH] libsdp: enable fallback to TCP for nonblocking sockets

Yossi Etigin yossi.openib at gmail.com
Wed Aug 20 09:20:45 PDT 2008


Enable falling back to tcp even if the socket is nonblocking by
doing the sdp connect() in blocking mode. This way, we know if 
sdp connection fails and can retry with tcp.

Signed-off-by: Yossi Etigin <yosefe at voltaire.com>

---
 src/port.c |   38 +++++++++++++-------------------------
 1 file changed, 13 insertions(+), 25 deletions(-)

Index: b/src/port.c
===================================================================
--- a/src/port.c	2008-08-18 22:32:33.000000000 +0300
+++ b/src/port.c	2008-08-20 19:09:43.000000000 +0300
@@ -1423,34 +1423,10 @@ connect(
 				  program_invocation_short_name, fd, shadow_fd,
 				  serv_sin->sin_family, buf, ntohs( serv_sin->sin_port ) );
 
-	fopts = _socket_funcs.fcntl(fd, F_GETFL);
-	__sdp_log( 1, "CONNECT: fd <%d> opts are <0x%x>\n",
-		   fd, fopts);
 
 	/* obtain the target address family */
 	target_family = __sdp_match_connect( serv_addr, addrlen );
 
-	if ( ( fopts & O_NONBLOCK ) &&
-	     ( target_family == USE_BOTH ) &&
-	     ( shadow_fd != -1 )) {
-		static int print_once = 1;
-
-		if ( print_once ) {
-			print_once = 0;
-			__sdp_log( 9, "CONNECT: libsdp does not support async connect in BOTH, moving to SDP only\n");
-		}
-
-		target_family = USE_SDP;
-		dup_ret = replace_fd_with_its_shadow( fd );
-		if ( dup_ret < 0 ) {
-			__sdp_log( 9, "Error connect: "
-				   "failed to dup2 shadow into orig fd:%d\n", fd );
-			ret = dup_ret;
-			goto done;
-		}
-		shadow_fd = -1;
-	}
-
 	/* if we do not have a shadow - just do the work */
 	if ( shadow_fd == -1 ) {
 		if ( get_is_sdp_socket( fd ) ) {
@@ -1498,6 +1474,15 @@ connect(
 #endif
 
 			__sdp_log( 1, "CONNECT: connecting SDP fd:%d\n", shadow_fd );
+
+			/* make the socket blocking on shadow SDP */
+			fopts = _socket_funcs.fcntl(shadow_fd, F_GETFL);
+			if ( ( target_family == USE_BOTH ) && ( fopts & O_NONBLOCK ) ) {
+				__sdp_log( 1, "CONNECT: shadow_fd <%d> will be blocking during connect\n",
+				           shadow_fd);
+				_socket_funcs.fcntl(shadow_fd, F_SETFL, fopts & (~O_NONBLOCK));
+			}
+
 			ret = _socket_funcs.connect( shadow_fd,
 												  ( struct sockaddr * )&sdp_addr,
 												  sizeof sdp_addr );
@@ -1509,6 +1494,9 @@ connect(
 				__sdp_log( 7, "CONNECT: connected SDP fd:%d to:%s port %d\n",
 							  fd, buf, ntohs( serv_sin->sin_port ) );
 			}
+
+			/* restore socket options */
+			_socket_funcs.fcntl(shadow_fd, F_SETFL, fopts);
 		}
 
 		/* if target is SDP or we succeeded we need to dup SDP fd into TCP fd */
@@ -1537,7 +1525,7 @@ connect(
 			__sdp_log( 7, "CONNECT: connected TCP fd:%d to:%s port %d\n",
 						  fd, buf, ntohs( serv_sin->sin_port ) );
 
-		if ( ( target_family == USE_TCP ) || ( ret >= 0 ) ) {
+		if ( ( target_family == USE_TCP ) || ( ret >= 0 ) || (errno == EINPROGRESS) ) {
 			if ( cleanup_shadow( fd ) < 0 )
 				__sdp_log( 9, "Error connect: failed to cleanup shadow for fd:%d\n",
 					   fd );



More information about the general mailing list