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
This commit is contained in:
Tobias Henkel 2020-01-16 09:03:36 +01:00
parent 103ad3e8ed
commit c9f23749c6
No known key found for this signature in database
GPG Key ID: 03750DEC158E5FA2
1 changed files with 8 additions and 2 deletions

View File

@ -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