aboutsummaryrefslogtreecommitdiffstats
path: root/netlib/tcp.py
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2012-07-08 23:50:38 +1200
committerAldo Cortesi <aldo@nullcube.com>2012-07-08 23:50:38 +1200
commitba7437abcbf3db11e227cae5e5c1d2df5975c77c (patch)
tree96099bd5cff7f01a6f50e070510cb0f8e64afc5b /netlib/tcp.py
parent20cc1b6aa4488d9b230469ba57b6a92380bfeeca (diff)
downloadmitmproxy-ba7437abcbf3db11e227cae5e5c1d2df5975c77c.tar.gz
mitmproxy-ba7437abcbf3db11e227cae5e5c1d2df5975c77c.tar.bz2
mitmproxy-ba7437abcbf3db11e227cae5e5c1d2df5975c77c.zip
Add an exception to indicate remote disconnects.
Diffstat (limited to 'netlib/tcp.py')
-rw-r--r--netlib/tcp.py21
1 files changed, 15 insertions, 6 deletions
diff --git a/netlib/tcp.py b/netlib/tcp.py
index 0af3d463..281a0438 100644
--- a/netlib/tcp.py
+++ b/netlib/tcp.py
@@ -36,6 +36,8 @@ OP_TLS_ROLLBACK_BUG = SSL.OP_TLS_ROLLBACK_BUG
class NetLibError(Exception): pass
+class NetLibDisconnect(Exception): pass
+
class FileLike:
def __init__(self, o):
@@ -61,7 +63,10 @@ class FileLike:
return result
def write(self, v):
- self.o.sendall(v)
+ try:
+ return self.o.sendall(v)
+ except SSL.SysCallError:
+ raise NetLibDisconnect()
def readline(self, size = None):
result = ''
@@ -159,11 +164,15 @@ class BaseHandler:
def finish(self):
self.finished = True
- if not getattr(self.wfile, "closed", False):
- self.wfile.flush()
- self.connection.close()
- self.wfile.close()
- self.rfile.close()
+ try:
+ if not getattr(self.wfile, "closed", False):
+ self.wfile.flush()
+ self.wfile.close()
+ self.rfile.close()
+ self.connection.close()
+ except socket.error:
+ # Remote has disconnected
+ pass
def handle_sni(self, connection):
"""