Show More
@@ -34,6 +34,7 b' from __future__ import absolute_import' | |||||
34 | import socket |
|
34 | import socket | |
35 |
|
35 | |||
36 | from mercurial import( |
|
36 | from mercurial import( | |
|
37 | pycompat, | |||
37 | registrar, |
|
38 | registrar, | |
38 | ) |
|
39 | ) | |
39 |
|
40 | |||
@@ -115,7 +116,7 b' class fileobjectproxy(object):' | |||||
115 | object.__setattr__(self, '_closeaftersendbytes', closeaftersendbytes) |
|
116 | object.__setattr__(self, '_closeaftersendbytes', closeaftersendbytes) | |
116 |
|
117 | |||
117 | def __getattribute__(self, name): |
|
118 | def __getattribute__(self, name): | |
118 | if name in ('read', 'readline', 'write', '_writelog'): |
|
119 | if name in ('_close', 'read', 'readline', 'write', '_writelog'): | |
119 | return object.__getattribute__(self, name) |
|
120 | return object.__getattribute__(self, name) | |
120 |
|
121 | |||
121 | return getattr(object.__getattribute__(self, '_orig'), name) |
|
122 | return getattr(object.__getattribute__(self, '_orig'), name) | |
@@ -133,6 +134,19 b' class fileobjectproxy(object):' | |||||
133 | object.__getattribute__(self, '_logfp').write(b'\n') |
|
134 | object.__getattribute__(self, '_logfp').write(b'\n') | |
134 | object.__getattribute__(self, '_logfp').flush() |
|
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 | def read(self, size=-1): |
|
150 | def read(self, size=-1): | |
137 | remaining = object.__getattribute__(self, '_closeafterrecvbytes') |
|
151 | remaining = object.__getattribute__(self, '_closeafterrecvbytes') | |
138 |
|
152 | |||
@@ -161,7 +175,8 b' class fileobjectproxy(object):' | |||||
161 |
|
175 | |||
162 | if remaining <= 0: |
|
176 | if remaining <= 0: | |
163 | self._writelog(b'read limit reached, closing socket') |
|
177 | self._writelog(b'read limit reached, closing socket') | |
164 |
self._ |
|
178 | self._close() | |
|
179 | ||||
165 | # This is the easiest way to abort the current request. |
|
180 | # This is the easiest way to abort the current request. | |
166 | raise Exception('connection closed after receiving N bytes') |
|
181 | raise Exception('connection closed after receiving N bytes') | |
167 |
|
182 | |||
@@ -194,7 +209,8 b' class fileobjectproxy(object):' | |||||
194 |
|
209 | |||
195 | if remaining <= 0: |
|
210 | if remaining <= 0: | |
196 | self._writelog(b'read limit reached; closing socket') |
|
211 | self._writelog(b'read limit reached; closing socket') | |
197 |
self._ |
|
212 | self._close() | |
|
213 | ||||
198 | # This is the easiest way to abort the current request. |
|
214 | # This is the easiest way to abort the current request. | |
199 | raise Exception('connection closed after receiving N bytes') |
|
215 | raise Exception('connection closed after receiving N bytes') | |
200 |
|
216 | |||
@@ -225,7 +241,8 b' class fileobjectproxy(object):' | |||||
225 |
|
241 | |||
226 | if remaining <= 0: |
|
242 | if remaining <= 0: | |
227 | self._writelog(b'write limit reached; closing socket') |
|
243 | self._writelog(b'write limit reached; closing socket') | |
228 |
self._ |
|
244 | self._close() | |
|
245 | ||||
229 | raise Exception('connection closed after sending N bytes') |
|
246 | raise Exception('connection closed after sending N bytes') | |
230 |
|
247 | |||
231 | return result |
|
248 | return result |
General Comments 0
You need to be logged in to leave comments.
Login now