Permalink
Browse files

Merge pull request #1 from luckythetourist/master

Added recv
  • Loading branch information...
2 parents c8cc7a0 + a366555 commit 37edc9a3c7c82f9d69e355d6aeee80a4ac55232a @lucky lucky committed Feb 13, 2012
Showing with 23 additions and 0 deletions.
  1. +23 −0 kiddiepool.py
View
23 kiddiepool.py
@@ -39,6 +39,10 @@ class KiddieClientSendFailure(socket.error):
"""KiddieClient failed to send request"""
+class KiddieClientRecvFailure(socket.error):
+ """KiddieClient failed to receive response"""
+
+
class KiddieConnection(object):
"""TCP Base Connection Class
@@ -95,6 +99,14 @@ def sendall(self, payload):
self.socket.sendall(payload)
self.touch()
+ def recv(self, size, flags=0):
+ data = self.socket.recv(size, flags)
+ self.touch()
+ return data
+
+ def recvall(self, size):
+ return self.recv(size, socket.MSG_WAITALL)
+
def handle_exception(self, e):
"""Close connection on socket errors"""
if isinstance(e, socket.error):
@@ -234,11 +246,22 @@ class KiddieClient(object):
"""
SendException = KiddieClientSendFailure
+ RecvException = KiddieClientRecvFailure
def __init__(self, pool, send_attempts=DEFAULT_SEND_ATTEMPTS):
self.pool = pool
self.send_attempts = send_attempts
+ def _recv(self, size):
+ """Recv -- No retry logic because that doesn't usually make sense"""
+ try:
+ with self.pool.connection() as conn:
+ return conn.recvall(size)
+ except socket.error as e:
+ raise self.RecvException('Failed to recv %s bytes. '
+ 'Last exception: %r ' % (size, e))
+
+
def _sendall(self, request, attempts=None):
"""Fire-and-forget with configurable retries"""
e = None

0 comments on commit 37edc9a

Please sign in to comment.