From a5f7752cf18a9c6b34916107abc89bbdf0050566 Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Thu, 10 Sep 2015 11:30:17 +0200 Subject: [PATCH] add ssl_read_select --- netlib/tcp.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/netlib/tcp.py b/netlib/tcp.py index 5c9d26de4..e9610099b 100644 --- a/netlib/tcp.py +++ b/netlib/tcp.py @@ -356,6 +356,27 @@ class Address(object): return hash(self.address) ^ 42 # different hash than the tuple alone. +def ssl_read_select(rlist, timeout): + """ + This is a wrapper around select.select() which also works for SSL.Connections + by taking ssl_connection.pending() into account. + + Caveats: + If .pending() > 0 for any of the connections in rlist, we avoid the select syscall + and **will not include any other connections which may or may not be ready**. + + Args: + rlist: wait until ready for reading + + Returns: + subset of rlist which is ready for reading. + """ + return [ + conn for conn in rlist + if isinstance(conn, SSL.Connection) and conn.pending() > 0 + ] or select.select(rlist, (), (), timeout)[0] + + def close_socket(sock): """ Does a hard close of a socket, without emitting a RST.