From c9f23749c6f4ae6933fbd800dace776fbb1362a0 Mon Sep 17 00:00:00 2001 From: Tobias Henkel Date: Thu, 16 Jan 2020 09:03:36 +0100 Subject: 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 --- gear/__init__.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'gear') 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 -- cgit v1.2.1