175
175
if time.time() >= end:
176
176
raise socket.timeout("timed out")
177
trampoline(fd, write=True, timeout=end-time.time(),
178
timeout_exc=socket.timeout("timed out"))
178
trampoline(fd, write=True, timeout=end-time.time(),
179
timeout_exc=socket.timeout("timed out"))
180
except socket.timeout, e:
182
if socket_connect(fd, address):
179
187
socket_checkerr(fd)
181
189
def connect_ex(self, address):
198
206
if time.time() >= end:
199
207
raise socket.timeout(errno.EAGAIN)
200
trampoline(fd, write=True, timeout=end-time.time(),
201
timeout_exc=socket.timeout(errno.EAGAIN))
209
trampoline(fd, write=True, timeout=end-time.time(),
210
timeout_exc=socket.timeout(errno.EAGAIN))
211
except socket.timeout, e:
213
if socket_connect(fd, address):
202
218
socket_checkerr(fd)
203
219
except socket.error, ex:
204
220
return get_errno(ex)
218
234
"makefile instead", DeprecationWarning, stacklevel=2)
219
235
return self.makefile(*args, **kw)
237
def _read_io(self, fd, f, *args, **kwargs):
238
if self.act_non_blocking:
239
return f(*args, **kwargs)
242
return f(*args, **kwargs)
243
except socket.error, e:
244
if get_errno(e) in SOCKET_BLOCKING:
246
# XXX -- Why does recv() do this?
247
elif f == fd.recv and get_errno(e) in SOCKET_CLOSED:
254
timeout=self.gettimeout(),
255
timeout_exc=socket.timeout("timed out"))
256
except socket.timeout, e:
257
# Try one last time to see if the timeout is 'real'
259
return f(*args, **kwargs)
221
263
def recv(self, buflen, flags=0):
223
if self.act_non_blocking:
224
return fd.recv(buflen, flags)
227
return fd.recv(buflen, flags)
228
except socket.error, e:
229
if get_errno(e) in SOCKET_BLOCKING:
231
elif get_errno(e) in SOCKET_CLOSED:
237
timeout=self.gettimeout(),
238
timeout_exc=socket.timeout("timed out"))
264
return self._read_io(self.fd, self.fd.recv, buflen, flags)
240
266
def recvfrom(self, *args):
241
if not self.act_non_blocking:
242
trampoline(self.fd, read=True, timeout=self.gettimeout(),
243
timeout_exc=socket.timeout("timed out"))
244
return self.fd.recvfrom(*args)
267
return self._read_io(self.fd, self.fd.recvfrom, *args)
246
269
def recvfrom_into(self, *args):
247
if not self.act_non_blocking:
248
trampoline(self.fd, read=True, timeout=self.gettimeout(),
249
timeout_exc=socket.timeout("timed out"))
250
return self.fd.recvfrom_into(*args)
270
return self._read_io(self.fd, self.fd.recvfrom_into, *args)
252
272
def recv_into(self, *args):
253
if not self.act_non_blocking:
254
trampoline(self.fd, read=True, timeout=self.gettimeout(),
255
timeout_exc=socket.timeout("timed out"))
256
return self.fd.recv_into(*args)
273
return self._read_io(self.fd, self.fd.recv_into, *args)
258
275
def send(self, data, flags=0):
274
291
if total_sent == len_data:
277
trampoline(self.fd, write=True, timeout=self.gettimeout(),
278
timeout_exc=socket.timeout("timed out"))
295
trampoline(fd, write=True, timeout=self.gettimeout(),
296
timeout_exc=socket.timeout("timed out"))
297
except socket.timeout, e:
298
# Try one last time to see if the timeout is 'real'
300
total_sent += fd.send(data[total_sent:], flags)
280
304
return total_sent
286
310
tail += self.send(data[tail:], flags)
288
312
def sendto(self, *args):
289
trampoline(self.fd, write=True)
290
return self.fd.sendto(*args)
314
if self.act_non_blocking:
315
return fd.sendto(*args)
318
return fd.sendto(*args)
319
except socket.error, e:
320
if get_errno(e) in SOCKET_BLOCKING:
325
trampoline(fd, write=True, timeout=self.gettimeout(),
326
timeout_exc=socket.timeout("timed out"))
327
except socket.timeout, e:
328
# Try one last time to see if the timeout is 'real'
330
return fd.sendto(*args)
292
334
def setblocking(self, flag):