summaryrefslogtreecommitdiffstats
path: root/module/remote/thriftbackend/Socket.py
diff options
context:
space:
mode:
Diffstat (limited to 'module/remote/thriftbackend/Socket.py')
-rw-r--r--module/remote/thriftbackend/Socket.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/module/remote/thriftbackend/Socket.py b/module/remote/thriftbackend/Socket.py
new file mode 100644
index 000000000..6ee850d07
--- /dev/null
+++ b/module/remote/thriftbackend/Socket.py
@@ -0,0 +1,31 @@
+# -*- coding: utf-8 -*-
+
+import socket
+
+from thrift.transport.TSocket import TSocket, TServerSocket, TTransportException
+
+
+class Socket(TSocket):
+ def __init__(self, host='localhost', port=7228, ssl=False):
+ TSocket.__init__(self, host, port)
+ self.ssl = ssl
+
+ def open(self):
+ self.handle = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+ self.handle.settimeout(self._timeout)
+ self.handle.connect((self.host, self.port))
+
+
+class ServerSocket(TServerSocket, Socket):
+ def __init__(self, port=7228, host="0.0.0.0", key="", cert=""):
+ self.host = host
+ self.port = port
+ self.handle = None
+
+ def listen(self):
+ self.handle = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+ self.handle.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
+ if hasattr(self.handle, 'set_timeout'):
+ self.handle.set_timeout(None)
+ self.handle.bind((self.host, self.port))
+ self.handle.listen(128) \ No newline at end of file