This commit is contained in:
Eugene Oden
2010-02-24 10:55:47 -05:00
2 changed files with 25 additions and 11 deletions

View File

@@ -281,24 +281,36 @@ class GreenSocket(object):
fd = self.fd fd = self.fd
if self.act_non_blocking: if self.act_non_blocking:
return fd.send(data, flags) return fd.send(data, flags)
# 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: 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(), trampoline(self.fd, write=True, timeout=self.gettimeout(),
timeout_exc=socket.timeout("timed out")) timeout_exc=socket.timeout("timed out"))
return fd.send(data, flags)
except socket.error, e: return total_sent
if e[0] in SOCKET_BLOCKING:
return 0
raise
def sendall(self, data, flags=0): def sendall(self, data, flags=0):
fd = self.fd fd = self.fd
tail = self.send(data, flags) tail = self.send(data, flags)
len_data = len(data) len_data = len(data)
while tail < 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) tail += self.send(data[tail:], flags)
def sendto(self, *args): def sendto(self, *args):

View File

@@ -160,6 +160,7 @@ class TestGreenIo(LimitedTestCase):
def server(): def server():
# accept the connection in another greenlet # accept the connection in another greenlet
sock, addr = listener.accept() sock, addr = listener.accept()
bufsized(sock, 1)
eventlet.sleep(.5) eventlet.sleep(.5)
@@ -171,9 +172,10 @@ class TestGreenIo(LimitedTestCase):
client.settimeout(0.1) client.settimeout(0.1)
client.connect(addr) client.connect(addr)
bufsized(client, 1)
try: try:
msg = "A"*(8*1024*1024) msg = "A"*min_buf_size()
# want to exceed the size of the OS buffer so it'll block # want to exceed the size of the OS buffer so it'll block
for x in range(10): for x in range(10):