[MERGE] merge with latest stable
[odoo/odoo.git] / bin / tiny_socket.py
index 387765d..44f7db0 100644 (file)
@@ -1,36 +1,44 @@
-# -*- encoding: utf-8 -*-
+# -*- coding: utf-8 -*-
 ##############################################################################
-#
-#    OpenERP, Open Source Management Solution  
-#    Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
-#    $Id$
+#    
+#    OpenERP, Open Source Management Solution
+#    Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
 #
 #    This program is free software: you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation, either version 3 of the License, or
-#    (at your option) any later version.
+#    it under the terms of the GNU Affero General Public License as
+#    published by the Free Software Foundation, either version 3 of the
+#    License, or (at your option) any later version.
 #
 #    This program is distributed in the hope that it will be useful,
 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
+#    GNU Affero General Public License for more details.
 #
-#    You should have received a copy of the GNU General Public License
-#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#    You should have received a copy of the GNU Affero General Public License
+#    along with this program.  If not, see <http://www.gnu.org/licenses/>.     
 #
 ##############################################################################
+
 import socket
 import cPickle
 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,25 +48,21 @@ 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)
-        self.sock.send('%8d' % size)
-        self.sock.send(exception and "1" or "0")
-        totalsent = 0
-        while totalsent < size:
-            sent = self.sock.send(msg[totalsent:])
-            if sent == 0:
-                raise RuntimeError, "socket connection broken"
-            totalsent = totalsent + sent
+        self.sock.sendall('%8d%s%s' % (len(msg), exception and "1" or "0", msg))
+            
     def myreceive(self):
         buf=''
         while len(buf) < 8:
@@ -89,6 +93,3 @@ class mysocket:
             raise res[0]
         else:
             return res[0]
-
-
-