Commit 1184b2fd authored by Ralf Schmitt's avatar Ralf Schmitt

use buffer object in order to prevent string copies

parent a6a68374
...@@ -327,7 +327,9 @@ class socket(object): ...@@ -327,7 +327,9 @@ class socket(object):
def recv(self, *args): def recv(self, *args):
while True: while True:
try: try:
return self._sock.recv(*args) res = self._sock.recv(*args)
#print 'received: %r' % (res, )
return res
except error, ex: except error, ex:
if ex[0] != EWOULDBLOCK or self.timeout == 0.0: if ex[0] != EWOULDBLOCK or self.timeout == 0.0:
raise raise
...@@ -366,6 +368,7 @@ class socket(object): ...@@ -366,6 +368,7 @@ class socket(object):
wait_read(self._sock.fileno(), timeout=self.timeout) wait_read(self._sock.fileno(), timeout=self.timeout)
def send(self, data, flags=0, timeout=timeout_default): def send(self, data, flags=0, timeout=timeout_default):
#print 'sending: %r' % data
if timeout is timeout_default: if timeout is timeout_default:
timeout = self.timeout timeout = self.timeout
try: try:
...@@ -388,13 +391,13 @@ class socket(object): ...@@ -388,13 +391,13 @@ class socket(object):
if self.timeout is None: if self.timeout is None:
data_sent = 0 data_sent = 0
while data_sent < len(data): while data_sent < len(data):
data_sent += self.send(data[data_sent:], flags) data_sent += self.send(buffer(data, data_sent), flags)
else: else:
timeleft = self.timeout timeleft = self.timeout
end = time.time() + timeleft end = time.time() + timeleft
data_sent = 0 data_sent = 0
while True: while True:
data_sent += self.send(data[data_sent:], flags, timeout=timeleft) data_sent += self.send(buffer(data, data_sent), flags, timeout=timeleft)
if data_sent >= len(data): if data_sent >= len(data):
break break
timeleft = end - time.time() timeleft = end - time.time()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment