diff options
author | Tobias Henkel <tobias.henkel@bmw.de> | 2020-01-16 09:03:36 +0100 |
---|---|---|
committer | Tobias Henkel <tobias.henkel@bmw.de> | 2020-01-16 09:11:51 +0100 |
commit | c9f23749c6f4ae6933fbd800dace776fbb1362a0 (patch) | |
tree | 5cb0ff5dbd34cef6a09e8eb541751df838614ed8 /gear | |
parent | 103ad3e8ed78c6895c425115fda45f28441bbfaf (diff) | |
download | gear-c9f23749c6f4ae6933fbd800dace776fbb1362a0.tar.gz |
Ignore keepalive on unsupported platforms
Gear currently supports keepalive only on linux platforms. On mac the
socket must be configured differently. For now just ignore the
keepalive flag in this case and emit a warning.
Change-Id: I276967b720742fa64e5bc6eb769c75590141275c
Diffstat (limited to 'gear')
-rw-r--r-- | gear/__init__.py | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/gear/__init__.py b/gear/__init__.py index 38b037a..55f804f 100644 --- a/gear/__init__.py +++ b/gear/__init__.py @@ -191,7 +191,7 @@ class Connection(object): af, socktype, proto, canonname, sa = res try: s = socket.socket(af, socktype, proto) - if self.keepalive: + if self.keepalive and hasattr(socket, 'TCP_KEEPIDLE'): s.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1) s.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPIDLE, self.tcp_keepidle) @@ -199,6 +199,9 @@ class Connection(object): self.tcp_keepintvl) s.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPCNT, self.tcp_keepcnt) + elif self.keepalive: + self.log.warning('Keepalive requested but not available ' + 'on this platform') except socket.error: s = None continue @@ -2810,7 +2813,7 @@ class Server(BaseClientServer): self.socket = socket.socket(af, socktype, proto) self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) - if keepalive: + if keepalive and hasattr(socket, 'TCP_KEEPIDLE'): self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1) self.socket.setsockopt(socket.IPPROTO_TCP, @@ -2819,6 +2822,9 @@ class Server(BaseClientServer): socket.TCP_KEEPINTVL, tcp_keepintvl) self.socket.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPCNT, tcp_keepcnt) + elif keepalive: + self.log.warning('Keepalive requested but not available ' + 'on this platform') except socket.error: self.socket = None continue |