mirror of
https://github.com/zahodi/ansible-mikrotik.git
synced 2025-06-21 17:39:03 +02:00
add mt_api library
This commit is contained in:
parent
f48bdb0d9e
commit
3609e520c5
4 changed files with 661 additions and 0 deletions
15
pythonlibs/mt_api/socket_utils.py
Normal file
15
pythonlibs/mt_api/socket_utils.py
Normal file
|
@ -0,0 +1,15 @@
|
|||
import socket
|
||||
|
||||
|
||||
# http://stackoverflow.com/a/14855726
|
||||
def set_keepalive(sock, after_idle_sec=1, interval_sec=3, max_fails=5):
|
||||
"""Set TCP keepalive on an open socket.
|
||||
|
||||
It activates after 1 second (after_idle_sec) of idleness,
|
||||
then sends a keepalive ping once every 3 seconds (interval_sec),
|
||||
and closes the connection after 5 failed ping (max_fails), or 15 seconds
|
||||
"""
|
||||
sock.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)
|
||||
sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPIDLE, after_idle_sec)
|
||||
sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPINTVL, interval_sec)
|
||||
sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPCNT, max_fails)
|
Loading…
Add table
Add a link
Reference in a new issue