aboutsummaryrefslogtreecommitdiffstats
path: root/netlib
diff options
context:
space:
mode:
authorMaximilian Hils <git@maximilianhils.com>2015-09-10 11:30:17 +0200
committerMaximilian Hils <git@maximilianhils.com>2015-09-10 11:30:41 +0200
commita5f7752cf18a9c6b34916107abc89bbdf0050566 (patch)
tree46035ce22c5ca6210cd9533e32ef44afe2bb1089 /netlib
parent32b3c32138847cb1f5b0c1958fc9ad0a49f8810f (diff)
downloadmitmproxy-a5f7752cf18a9c6b34916107abc89bbdf0050566.tar.gz
mitmproxy-a5f7752cf18a9c6b34916107abc89bbdf0050566.tar.bz2
mitmproxy-a5f7752cf18a9c6b34916107abc89bbdf0050566.zip
add ssl_read_select
Diffstat (limited to 'netlib')
-rw-r--r--netlib/tcp.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/netlib/tcp.py b/netlib/tcp.py
index 5c9d26de..e9610099 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.