From 495939982bfebf856332f36c0d8a04ce89d4b889 Mon Sep 17 00:00:00 2001 From: Eugene Oden Date: Wed, 24 Feb 2010 10:55:20 -0500 Subject: [PATCH] working on blocking send, which still isn't quite right reopens #38 --- eventlet/greenio.py | 32 ++++++++++++++++++++++---------- tests/greenio_test.py | 4 +++- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/eventlet/greenio.py b/eventlet/greenio.py index 1d305ea..ea970ac 100644 --- a/eventlet/greenio.py +++ b/eventlet/greenio.py @@ -283,24 +283,36 @@ class GreenSocket(object): fd = self.fd if self.act_non_blocking: return fd.send(data, flags) - try: + + # XXX: need to deal with the exceptions that could be raised if the + # buffer is full (specifically the try/except below) + + # need to test all of the conditions + + # blocking socket behavior - sends all, blocks if the buffer is full + total_sent = 0 + len_data = len(data) + + while 1: + try: + total_sent += fd.send(data[total_sent:], flags) + except socket.error, e: + if e[0] not in SOCKET_BLOCKING: + raise + + if total_sent == len_data: + break + trampoline(self.fd, write=True, timeout=self.gettimeout(), timeout_exc=socket.timeout("timed out")) - return fd.send(data, flags) - except socket.error, e: - if e[0] in SOCKET_BLOCKING: - return 0 - raise + + return total_sent def sendall(self, data, flags=0): fd = self.fd tail = self.send(data, flags) len_data = len(data) while tail < len_data: - trampoline(fd, - write=True, - timeout=self.timeout, - timeout_exc=socket.timeout("timed out")) tail += self.send(data[tail:], flags) def sendto(self, *args): diff --git a/tests/greenio_test.py b/tests/greenio_test.py index 0aa8823..7f5354c 100644 --- a/tests/greenio_test.py +++ b/tests/greenio_test.py @@ -160,6 +160,7 @@ class TestGreenIo(LimitedTestCase): def server(): # accept the connection in another greenlet sock, addr = listener.accept() + bufsized(sock, 1) eventlet.sleep(.5) @@ -171,9 +172,10 @@ class TestGreenIo(LimitedTestCase): client.settimeout(0.1) client.connect(addr) + bufsized(client, 1) try: - msg = "A"*(8*1024*1024) + msg = "A"*min_buf_size() # want to exceed the size of the OS buffer so it'll block for x in range(10):