diff mbox

[v5,4/4] rsockets: Support calling listen multiple times on same rsocket

Message ID 0a6a8d14f8b06bab2682dd4e555c315d@imap.linux.ibm.com (mailing list archive)
State Not Applicable, archived
Headers show

Commit Message

Sreedhar Kodali Sept. 18, 2014, 10:50 a.m. UTC
Note: The modified fix from Sean is being resent for completeness of 
changes
       Also attached the patch file for convenience

 From: Sreedhar Kodali <srkodali@linux.vnet.ibm.com>
Date:   Thu Sep 18 14:51:58 2014 +0530

     Standard sockets allows an application to call listen() multiple
     times on the same socket without error.  This allows a 
multi-threaded
     app to call listen from all threads.

     rsockets will fail the second listen call.  Modify the behavior to
     match standard sockets.

     Problem reported by: Sreedhar Kodali <srkodali@linux.vnet.ibm.com>

     Signed-off-by: Sean Hefty <sean.hefty@intel.com>
     ---
commit 79d3f5cbfc92b48de33ad1cd22437aa6ce24cc52
Author: Sreedhar Kodali <srkodali@linux.vnet.ibm.com>
Date:   Thu Sep 18 14:51:58 2014 +0530

    Standard sockets allows an application to call listen() multiple
    times on the same socket without error.  This allows a multi-threaded
    app to call listen from all threads.
    
    rsockets will fail the second listen call.  Modify the behavior to
    match standard sockets.
    
    Problem reported by: Sreedhar Kodali <srkodali@linux.vnet.ibm.com>
    
    Signed-off-by: Sean Hefty <sean.hefty@intel.com>
    ---

diff --git a/src/rsocket.c b/src/rsocket.c
index 16792cf..ae72a00 100644
--- a/src/rsocket.c
+++ b/src/rsocket.c
@@ -1179,9 +1179,15 @@ int rlisten(int socket, int backlog)
 	rs = idm_lookup(&idm, socket);
 	if (!rs)
 		return ERR(EBADF);
-	ret = rdma_listen(rs->cm_id, backlog);
-	if (!ret)
-		rs->state = rs_listening;
+
+	if (rs->state != rs_listening) {
+		ret = rdma_listen(rs->cm_id, backlog);
+		if (!ret)
+			rs->state = rs_listening;
+	} else {
+		ret = 0;
+	}
+
 	return ret;
 }
diff mbox

Patch

diff --git a/src/rsocket.c b/src/rsocket.c
index 16792cf..ae72a00 100644
--- a/src/rsocket.c
+++ b/src/rsocket.c
@@ -1179,9 +1179,15 @@  int rlisten(int socket, int backlog)
         rs = idm_lookup(&idm, socket);
         if (!rs)
                 return ERR(EBADF);
-       ret = rdma_listen(rs->cm_id, backlog);
-       if (!ret)
-               rs->state = rs_listening;
+
+       if (rs->state != rs_listening) {
+               ret = rdma_listen(rs->cm_id, backlog);
+               if (!ret)
+                       rs->state = rs_listening;
+       } else {
+               ret = 0;
+       }
+
         return ret;
  }