]> www.average.org Git - loctrkd.git/commitdiff
collector: enable SO_KEEPALIVE on accepted conn.
authorEugene Crosser <crosser@average.org>
Thu, 16 Jun 2022 21:17:25 +0000 (23:17 +0200)
committerEugene Crosser <crosser@average.org>
Thu, 16 Jun 2022 21:17:25 +0000 (23:17 +0200)
Terminals have a bad habit to drop off the network without closing the
connection. That will leave the server with orphan connections
accumulating over time.

gps303/collector.py

index c2efd79b82182e13319526a644abccb0e85071b9..ef80cc534c0a9683f5219fc676fddb0bd0708d69 100644 (file)
@@ -3,7 +3,14 @@
 from configparser import ConfigParser
 from logging import getLogger
 from os import umask
-from socket import socket, AF_INET6, SOCK_STREAM, SOL_SOCKET, SO_REUSEADDR
+from socket import (
+    socket,
+    AF_INET6,
+    SOCK_STREAM,
+    SOL_SOCKET,
+    SO_KEEPALIVE,
+    SO_REUSEADDR,
+)
 from struct import pack
 from time import time
 from typing import Dict, List, Optional, Tuple
@@ -206,6 +213,7 @@ def runserver(conf: ConfigParser, handle_hibernate: bool = True) -> None:
                             break
                 elif sk == tcpfd:
                     clntsock, clntaddr = tcpl.accept()
+                    clntsock.setsockopt(SOL_SOCKET, SO_KEEPALIVE, 1)
                     topoll.append((clntsock, clntaddr))
                 elif fl & zmq.POLLIN:
                     received = clients.recv(sk)