##// END OF EJS Templates
tests: change how sockets are closed...
Gregory Szorc -
r41605:d343d9ac default
parent child Browse files
Show More
@@ -34,6 +34,7 b' from __future__ import absolute_import'
34 34 import socket
35 35
36 36 from mercurial import(
37 pycompat,
37 38 registrar,
38 39 )
39 40
@@ -115,7 +116,7 b' class fileobjectproxy(object):'
115 116 object.__setattr__(self, '_closeaftersendbytes', closeaftersendbytes)
116 117
117 118 def __getattribute__(self, name):
118 if name in ('read', 'readline', 'write', '_writelog'):
119 if name in ('_close', 'read', 'readline', 'write', '_writelog'):
119 120 return object.__getattribute__(self, name)
120 121
121 122 return getattr(object.__getattribute__(self, '_orig'), name)
@@ -133,6 +134,19 b' class fileobjectproxy(object):'
133 134 object.__getattribute__(self, '_logfp').write(b'\n')
134 135 object.__getattribute__(self, '_logfp').flush()
135 136
137 def _close(self):
138 # Python 3 uses an io.BufferedIO instance. Python 2 uses some file
139 # object wrapper.
140 if pycompat.ispy3:
141 orig = object.__getattribute__(self, '_orig')
142
143 if hasattr(orig, 'raw'):
144 orig.raw._sock.shutdown(socket.SHUT_RDWR)
145 else:
146 self.close()
147 else:
148 self._sock.shutdown(socket.SHUT_RDWR)
149
136 150 def read(self, size=-1):
137 151 remaining = object.__getattribute__(self, '_closeafterrecvbytes')
138 152
@@ -161,7 +175,8 b' class fileobjectproxy(object):'
161 175
162 176 if remaining <= 0:
163 177 self._writelog(b'read limit reached, closing socket')
164 self._sock.close()
178 self._close()
179
165 180 # This is the easiest way to abort the current request.
166 181 raise Exception('connection closed after receiving N bytes')
167 182
@@ -194,7 +209,8 b' class fileobjectproxy(object):'
194 209
195 210 if remaining <= 0:
196 211 self._writelog(b'read limit reached; closing socket')
197 self._sock.close()
212 self._close()
213
198 214 # This is the easiest way to abort the current request.
199 215 raise Exception('connection closed after receiving N bytes')
200 216
@@ -225,7 +241,8 b' class fileobjectproxy(object):'
225 241
226 242 if remaining <= 0:
227 243 self._writelog(b'write limit reached; closing socket')
228 self._sock.close()
244 self._close()
245
229 246 raise Exception('connection closed after sending N bytes')
230 247
231 248 return result
General Comments 0
You need to be logged in to leave comments. Login now