diff options
author | martinko | 2013-07-10 10:14:37 +0000 |
---|---|---|
committer | martinko | 2013-07-10 10:14:37 +0000 |
commit | e0bd01f65868cd05f78dd0028237c5a46987b81e (patch) | |
tree | 3135b08bec2fba2a25e42c12236bb0573d4e1582 /python/skytools | |
parent | 022cb5c1fa7722018d852ce4658f0f8fbc09e99d (diff) | |
parent | 048a0888600c1de9cbc733280d641022ac986ae0 (diff) |
Merge branch 'master' of https://github.com/markokr/skytools into develop
Diffstat (limited to 'python/skytools')
-rw-r--r-- | python/skytools/sockutil.py | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/python/skytools/sockutil.py b/python/skytools/sockutil.py index f950f5a0..dbcd021b 100644 --- a/python/skytools/sockutil.py +++ b/python/skytools/sockutil.py @@ -37,10 +37,13 @@ def set_tcp_keepalive(fd, keepalive = True, if not hasattr(socket, 'SO_KEEPALIVE') or not hasattr(socket, 'fromfd'): return - # get numeric fd and cast to socket - if hasattr(fd, 'fileno'): - fd = fd.fileno() - s = socket.fromfd(fd, socket.AF_INET, socket.SOCK_STREAM) + # need socket object + if isinstance(fd, socket.SocketType): + s = fd + else: + if hasattr(fd, 'fileno'): + fd = fd.fileno() + s = socket.fromfd(fd, socket.AF_INET, socket.SOCK_STREAM) # skip if unix socket if type(s.getsockname()) != type(()): |