summaryrefslogtreecommitdiff
path: root/bin/tiny_socket.py
diff options
context:
space:
mode:
authorMantavya Gajjar <mga@mga>2010-03-11 11:21:33 +0530
committerMantavya Gajjar <mga@mga>2010-03-11 11:21:33 +0530
commit44b340bf91f52d0341f58f73796c5de34677065a (patch)
tree0178653bc2bd45bdc6d056fa8095de94fb2fb545 /bin/tiny_socket.py
parent1c2abb3388e0ba1c459f9a583a3561f17fb5e48c (diff)
[REVIEW]: code formatting and add comment
* remove tabs and place space(4) bzr revid: mga@mga-20100311055133-cftf0r5zuya3uax8
Diffstat (limited to 'bin/tiny_socket.py')
-rw-r--r--bin/tiny_socket.py15
1 files changed, 12 insertions, 3 deletions
diff --git a/bin/tiny_socket.py b/bin/tiny_socket.py
index cb51aefc140..6a0d9371ef5 100644
--- a/bin/tiny_socket.py
+++ b/bin/tiny_socket.py
@@ -25,12 +25,20 @@ import cStringIO
import marshal
class Myexception(Exception):
+ """
+ custome exception object store
+ * faultcode
+ * faulestring
+ * args
+ """
+
def __init__(self, faultCode, faultString):
self.faultCode = faultCode
self.faultString = faultString
self.args = (faultCode, faultString)
class mysocket:
+
def __init__(self, sock=None):
if sock is None:
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
@@ -40,14 +48,17 @@ class mysocket:
# 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('//')
host, port = buf.split(':')
self.sock.connect((host, int(port)))
+
def disconnect(self):
self.sock.shutdown(socket.SHUT_RDWR)
self.sock.close()
+
def mysend(self, msg, exception=False, traceback=None):
msg = cPickle.dumps([msg,traceback])
size = len(msg)
@@ -59,6 +70,7 @@ class mysocket:
if sent == 0:
raise RuntimeError, "socket connection broken"
totalsent = totalsent + sent
+
def myreceive(self):
buf=''
while len(buf) < 8:
@@ -89,6 +101,3 @@ class mysocket:
raise res[0]
else:
return res[0]
-
-
-