You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by jf...@apache.org on 2013/11/25 20:48:11 UTC

git commit: THRIFT-2267:Should be able to choose socket family in Python TSocket Client: py Patch: Abraham Elmahrek

Updated Branches:
  refs/heads/master cba92b308 -> 3979b869f


THRIFT-2267:Should be able to choose socket family in Python TSocket
Client: py
Patch: Abraham Elmahrek

Currenlty, the python library looks for AF_INET6, but some applications prefer AF_INET4. This should be selectable or configurable.


Project: http://git-wip-us.apache.org/repos/asf/thrift/repo
Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/3979b869
Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/3979b869
Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/3979b869

Branch: refs/heads/master
Commit: 3979b869f3236b3a7e1c92b788eabced2a8345ed
Parents: cba92b3
Author: jfarrell <jf...@apache.org>
Authored: Mon Nov 25 14:47:16 2013 -0500
Committer: jfarrell <jf...@apache.org>
Committed: Mon Nov 25 14:47:16 2013 -0500

----------------------------------------------------------------------
 lib/py/src/transport/TSocket.py | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/thrift/blob/3979b869/lib/py/src/transport/TSocket.py
----------------------------------------------------------------------
diff --git a/lib/py/src/transport/TSocket.py b/lib/py/src/transport/TSocket.py
index 9e2b384..d72cf2b 100644
--- a/lib/py/src/transport/TSocket.py
+++ b/lib/py/src/transport/TSocket.py
@@ -33,7 +33,7 @@ class TSocketBase(TTransportBase):
     else:
       return socket.getaddrinfo(self.host,
                                 self.port,
-                                socket.AF_UNSPEC,
+                                socket.self._socket_family,
                                 socket.SOCK_STREAM,
                                 0,
                                 socket.AI_PASSIVE | socket.AI_ADDRCONFIG)
@@ -47,19 +47,21 @@ class TSocketBase(TTransportBase):
 class TSocket(TSocketBase):
   """Socket implementation of TTransport base."""
 
-  def __init__(self, host='localhost', port=9090, unix_socket=None):
+  def __init__(self, host='localhost', port=9090, unix_socket=None, socket_family=socket.AF_UNSPEC):
     """Initialize a TSocket
 
     @param host(str)  The host to connect to.
     @param port(int)  The (TCP) port to connect to.
     @param unix_socket(str)  The filename of a unix socket to connect to.
                              (host and port will be ignored.)
+    @param socket_family(int)  The socket family to use with this socket.
     """
     self.host = host
     self.port = port
     self.handle = None
     self._unix_socket = unix_socket
     self._timeout = None
+    self._socket_family = socket_family
 
   def setHandle(self, h):
     self.handle = h
@@ -139,16 +141,18 @@ class TSocket(TSocketBase):
 class TServerSocket(TSocketBase, TServerTransportBase):
   """Socket implementation of TServerTransport base."""
 
-  def __init__(self, host=None, port=9090, unix_socket=None):
+  def __init__(self, host=None, port=9090, unix_socket=None, socket_family=socket.AF_UNSPEC):
     self.host = host
     self.port = port
     self._unix_socket = unix_socket
+    self._socket_family = socket_family
     self.handle = None
 
   def listen(self):
     res0 = self._resolveAddr()
+    socket_family = self._socket_family == socket.AF_UNSPEC and socket.AF_INET6 or self._socket_family
     for res in res0:
-      if res[0] is socket.AF_INET6 or res is res0[-1]:
+      if res[0] is socket_family or res is res0[-1]:
         break
 
     # We need remove the old unix socket if the file exists and