Skip to content

Commit

Permalink
Merge pull request #251 from thomasgoirand/master
Browse files Browse the repository at this point in the history
TCP_KEEPCNT doesn't exist in non-linux
  • Loading branch information
DirectXMan12 authored Oct 10, 2016
2 parents 72ce5c1 + 325e4ef commit cb1508f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
10 changes: 6 additions & 4 deletions tests/test_websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,9 @@ def test_socket_set_keepalive_options(self):
tcp_keepidle=keepidle,
tcp_keepintvl=keepintvl)

self.assertEqual(sock.getsockopt(socket.SOL_TCP,
socket.TCP_KEEPCNT), keepcnt)
if hasattr(socket, 'TCP_KEEPCNT'):
self.assertEqual(sock.getsockopt(socket.SOL_TCP,
socket.TCP_KEEPCNT), keepcnt)
self.assertEqual(sock.getsockopt(socket.SOL_TCP,
socket.TCP_KEEPIDLE), keepidle)
self.assertEqual(sock.getsockopt(socket.SOL_TCP,
Expand All @@ -337,8 +338,9 @@ def test_socket_set_keepalive_options(self):
tcp_keepidle=keepidle,
tcp_keepintvl=keepintvl)

self.assertNotEqual(sock.getsockopt(socket.SOL_TCP,
socket.TCP_KEEPCNT), keepcnt)
if hasattr(socket, 'TCP_KEEPCNT'):
self.assertNotEqual(sock.getsockopt(socket.SOL_TCP,
socket.TCP_KEEPCNT), keepcnt)
self.assertNotEqual(sock.getsockopt(socket.SOL_TCP,
socket.TCP_KEEPIDLE), keepidle)
self.assertNotEqual(sock.getsockopt(socket.SOL_TCP,
Expand Down
7 changes: 5 additions & 2 deletions websockify/websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -723,8 +723,11 @@ def socket(host, port=None, connect=False, prefer_ipv6=False,
if tcp_keepalive:
sock.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)
if tcp_keepcnt:
sock.setsockopt(socket.SOL_TCP, socket.TCP_KEEPCNT,
tcp_keepcnt)
if hasattr(socket, 'TCP_KEEPCNT'):
sock.setsockopt(socket.SOL_TCP, socket.TCP_KEEPCNT,
tcp_keepcnt)
else:
self.msg('tcp_keepcnt not available on your system')
if tcp_keepidle:
sock.setsockopt(socket.SOL_TCP, socket.TCP_KEEPIDLE,
tcp_keepidle)
Expand Down

0 comments on commit cb1508f

Please sign in to comment.