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
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):

View File

@@ -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):