summaryrefslogtreecommitdiff
path: root/bin/tiny_socket.py
diff options
context:
space:
mode:
authorMantavya Gajjar <mga@tinyerp.com>2009-11-26 17:06:53 +0530
committerMantavya Gajjar <mga@tinyerp.com>2009-11-26 17:06:53 +0530
commitbbe48761e4d9c6d9844bae92dac61afc7ec0ce99 (patch)
tree180fa5b70de5c2c518e0ecf0079c02c643e6e109 /bin/tiny_socket.py
parentd365fbeb13fe41e30535d0bdbbdbca969ca818f2 (diff)
parentb7f7fdefaf58ef3e183a450b68a8796ca2bdaf24 (diff)
[MERGE]: merging from the same branch
bzr revid: mga@tinyerp.com-20091126113653-0ym60nvtjinvp82h
Diffstat (limited to 'bin/tiny_socket.py')
-rw-r--r--bin/tiny_socket.py16
1 files changed, 9 insertions, 7 deletions
diff --git a/bin/tiny_socket.py b/bin/tiny_socket.py
index 746d6c22671..cb51aefc140 100644
--- a/bin/tiny_socket.py
+++ b/bin/tiny_socket.py
@@ -33,11 +33,13 @@ class Myexception(Exception):
class mysocket:
def __init__(self, sock=None):
if sock is None:
- self.sock = socket.socket(
- socket.AF_INET, socket.SOCK_STREAM)
+ self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
else:
self.sock = sock
- self.sock.settimeout(120)
+ # self.sock.settimeout(120)
+ # prepare this socket for long operations: it may block for infinite
+ # time, but should exit as soon as the net is down
+ self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)
def connect(self, host, port=False):
if not port:
protocol, buf = host.split('//')
@@ -61,8 +63,8 @@ class mysocket:
buf=''
while len(buf) < 8:
chunk = self.sock.recv(8 - len(buf))
- if chunk == '':
- raise RuntimeError, "socket connection broken"
+ if not chunk:
+ raise socket.timeout
buf += chunk
size = int(buf)
buf = self.sock.recv(1)
@@ -73,8 +75,8 @@ class mysocket:
msg = ''
while len(msg) < size:
chunk = self.sock.recv(size-len(msg))
- if chunk == '':
- raise RuntimeError, "socket connection broken"
+ if not chunk:
+ raise socket.timeout
msg = msg + chunk
msgio = cStringIO.StringIO(msg)
unpickler = cPickle.Unpickler(msgio)