You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ch...@apache.org on 2021/05/17 14:09:08 UTC

[qpid-dispatch] 01/02: DISPATCH-2100: Self test for TCP half-closed handling

This is an automated email from the ASF dual-hosted git repository.

chug pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/qpid-dispatch.git

commit 42b9bbce19320d1743ef3e063863fe8608dc2546
Author: Chuck Rolke <ch...@apache.org>
AuthorDate: Thu May 6 15:31:50 2021 -0400

    DISPATCH-2100: Self test for TCP half-closed handling
    
    This patch improves the echo server program half-closed handling.
    
    When the client socket closes ensure that data received from the
    client is echoed back to the client before closing the socket
    from the server end.
---
 tests/TCP_echo_server.py | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/tests/TCP_echo_server.py b/tests/TCP_echo_server.py
index 678132c..47dcb4f 100755
--- a/tests/TCP_echo_server.py
+++ b/tests/TCP_echo_server.py
@@ -230,7 +230,25 @@ class TcpEchoServer:
                                                                split_chunk_for_display(recv_data)))
                 sel.modify(sock, selectors.EVENT_READ | selectors.EVENT_WRITE, data=data)
             else:
-                logger.log('%s Closing connection to %s:%d' % (self.prefix, data.addr[0], data.addr[1]))
+                while data.outb:
+                    logger.log('%s Client closed: flush client input to %s:%d' % (self.prefix, data.addr[0], data.addr[1]))
+                    try:
+                        sent = sock.send(data.outb)
+                        data.outb = data.outb[sent:]
+                    except IOError:
+                        logger.log('%s Connection to %s:%d IOError: %s' %
+                                   (self.prefix, data.addr[0], data.addr[1], traceback.format_exc()))
+                        sel.unregister(sock)
+                        sock.close()
+                        return 0
+                    except Exception:
+                        self.error = ('%s Connection to %s:%d exception: %s' %
+                                      (self.prefix, data.addr[0], data.addr[1], traceback.format_exc()))
+                        logger.log(self.error)
+                        sel.unregister(sock)
+                        sock.close()
+                        return 1
+                logger.log('%s Client closed: closing connection to %s:%d' % (self.prefix, data.addr[0], data.addr[1]))
                 sel.unregister(sock)
                 sock.close()
                 return 0

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org