Python socket.SIO_KEEPALIVE_VALS Examples
The following are 14
code examples of socket.SIO_KEEPALIVE_VALS().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
socket
, or try the search function
.
Example #1
Source File: transport.py From NVDARemote with GNU General Public License v2.0 | 5 votes |
def create_outbound_socket(self, address): address = socket.getaddrinfo(*address)[0] server_sock = socket.socket(*address[:3]) if self.timeout: server_sock.settimeout(self.timeout) server_sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1) server_sock.ioctl(socket.SIO_KEEPALIVE_VALS, (1, 60000, 2000)) server_sock = ssl.wrap_socket(server_sock) return server_sock
Example #2
Source File: test_socket.py From ironpython2 with Apache License 2.0 | 5 votes |
def test_sock_ioctl(self): self.assertTrue(hasattr(socket.socket, 'ioctl')) self.assertTrue(hasattr(socket, 'SIO_RCVALL')) self.assertTrue(hasattr(socket, 'RCVALL_ON')) self.assertTrue(hasattr(socket, 'RCVALL_OFF')) self.assertTrue(hasattr(socket, 'SIO_KEEPALIVE_VALS')) s = socket.socket() self.addCleanup(s.close) self.assertRaises(ValueError, s.ioctl, -1, None) s.ioctl(socket.SIO_KEEPALIVE_VALS, (1, 100, 100))
Example #3
Source File: pool.py From vnpy_crypto with MIT License | 5 votes |
def _set_keepalive_times(sock): idle_ms = min(_DEFAULT_TCP_IDLE_MS, _MAX_TCP_KEEPIDLE * 1000) interval_ms = min(_DEFAULT_TCP_INTERVAL_MS, _MAX_TCP_KEEPINTVL * 1000) if (idle_ms < _DEFAULT_TCP_IDLE_MS or interval_ms < _DEFAULT_TCP_INTERVAL_MS): sock.ioctl(socket.SIO_KEEPALIVE_VALS, (1, idle_ms, interval_ms))
Example #4
Source File: test_socket.py From BinderFilter with MIT License | 5 votes |
def test_sock_ioctl(self): self.assertTrue(hasattr(socket.socket, 'ioctl')) self.assertTrue(hasattr(socket, 'SIO_RCVALL')) self.assertTrue(hasattr(socket, 'RCVALL_ON')) self.assertTrue(hasattr(socket, 'RCVALL_OFF')) self.assertTrue(hasattr(socket, 'SIO_KEEPALIVE_VALS')) s = socket.socket() self.addCleanup(s.close) self.assertRaises(ValueError, s.ioctl, -1, None) s.ioctl(socket.SIO_KEEPALIVE_VALS, (1, 100, 100))
Example #5
Source File: test_socket.py From oss-ftp with MIT License | 5 votes |
def test_sock_ioctl(self): self.assertTrue(hasattr(socket.socket, 'ioctl')) self.assertTrue(hasattr(socket, 'SIO_RCVALL')) self.assertTrue(hasattr(socket, 'RCVALL_ON')) self.assertTrue(hasattr(socket, 'RCVALL_OFF')) self.assertTrue(hasattr(socket, 'SIO_KEEPALIVE_VALS')) s = socket.socket() self.addCleanup(s.close) self.assertRaises(ValueError, s.ioctl, -1, None) s.ioctl(socket.SIO_KEEPALIVE_VALS, (1, 100, 100))
Example #6
Source File: ksocket.py From marsnake with GNU General Public License v3.0 | 5 votes |
def start(self): family, socktype, proto, _, sockaddr = socket.getaddrinfo(self.host, self.port, self.family, self.type)[0] sock = socket.socket(family, socktype) sock.connect(sockaddr) if self.nodelay: sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1) if self.keepalive: sock.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1) if hasattr(socket, "TCP_KEEPIDLE") and hasattr(socket, "TCP_KEEPINTVL") and hasattr(socket, "TCP_KEEPCNT"): sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPIDLE, 1 * 60) sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPINTVL, 30) sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPCNT, 5) elif hasattr(socket, "SIO_KEEPALIVE_VALS"): sock.ioctl(socket.SIO_KEEPALIVE_VALS, (1, 1 * 60 * 1000, 5 * 60 * 1000)) self.sock = sock self.recv_count = 0 Ksecurity().reset_aes()
Example #7
Source File: test_socket.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def test_sock_ioctl(self): self.assertTrue(hasattr(socket.socket, 'ioctl')) self.assertTrue(hasattr(socket, 'SIO_RCVALL')) self.assertTrue(hasattr(socket, 'RCVALL_ON')) self.assertTrue(hasattr(socket, 'RCVALL_OFF')) self.assertTrue(hasattr(socket, 'SIO_KEEPALIVE_VALS')) s = socket.socket() self.addCleanup(s.close) self.assertRaises(ValueError, s.ioctl, -1, None) s.ioctl(socket.SIO_KEEPALIVE_VALS, (1, 100, 100))
Example #8
Source File: pool.py From learn_python3_spider with MIT License | 5 votes |
def _set_keepalive_times(sock): idle_ms = min(_DEFAULT_TCP_IDLE_MS, _MAX_TCP_KEEPIDLE * 1000) interval_ms = min(_DEFAULT_TCP_INTERVAL_MS, _MAX_TCP_KEEPINTVL * 1000) if (idle_ms < _DEFAULT_TCP_IDLE_MS or interval_ms < _DEFAULT_TCP_INTERVAL_MS): sock.ioctl(socket.SIO_KEEPALIVE_VALS, (1, idle_ms, interval_ms))
Example #9
Source File: test_socket.py From ironpython3 with Apache License 2.0 | 5 votes |
def test_sock_ioctl(self): self.assertTrue(hasattr(socket.socket, 'ioctl')) self.assertTrue(hasattr(socket, 'SIO_RCVALL')) self.assertTrue(hasattr(socket, 'RCVALL_ON')) self.assertTrue(hasattr(socket, 'RCVALL_OFF')) self.assertTrue(hasattr(socket, 'SIO_KEEPALIVE_VALS')) s = socket.socket() self.addCleanup(s.close) self.assertRaises(ValueError, s.ioctl, -1, None) s.ioctl(socket.SIO_KEEPALIVE_VALS, (1, 100, 100))
Example #10
Source File: test_socket.py From gcblue with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_sock_ioctl(self): self.assertTrue(hasattr(socket.socket, 'ioctl')) self.assertTrue(hasattr(socket, 'SIO_RCVALL')) self.assertTrue(hasattr(socket, 'RCVALL_ON')) self.assertTrue(hasattr(socket, 'RCVALL_OFF')) self.assertTrue(hasattr(socket, 'SIO_KEEPALIVE_VALS')) s = socket.socket() self.addCleanup(s.close) self.assertRaises(ValueError, s.ioctl, -1, None) s.ioctl(socket.SIO_KEEPALIVE_VALS, (1, 100, 100))
Example #11
Source File: test_socket.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_sock_ioctl(self): self.assertTrue(hasattr(socket.socket, 'ioctl')) self.assertTrue(hasattr(socket, 'SIO_RCVALL')) self.assertTrue(hasattr(socket, 'RCVALL_ON')) self.assertTrue(hasattr(socket, 'RCVALL_OFF')) self.assertTrue(hasattr(socket, 'SIO_KEEPALIVE_VALS')) s = socket.socket() self.addCleanup(s.close) self.assertRaises(ValueError, s.ioctl, -1, None) s.ioctl(socket.SIO_KEEPALIVE_VALS, (1, 100, 100))
Example #12
Source File: sock.py From pyp2p with MIT License | 5 votes |
def set_keep_alive(self, sock, after_idle_sec=5, interval_sec=60, max_fails=5): """ This function instructs the TCP socket to send a heart beat every n seconds to detect dead connections. It's the TCP equivalent of the IRC ping-pong protocol and allows for better cleanup / detection of dead TCP connections. 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 """ # OSX if platform.system() == "Darwin": # scraped from /usr/include, not exported by python's socket module TCP_KEEPALIVE = 0x10 sock.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1) sock.setsockopt(socket.IPPROTO_TCP, TCP_KEEPALIVE, interval_sec) if platform.system() == "Windows": sock.ioctl(socket.SIO_KEEPALIVE_VALS, (1, 10000, 3000)) if platform.system() == "Linux": 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)
Example #13
Source File: Chemputer_Device_API.py From ChemputerSoftware with BSD 3-Clause "New" or "Revised" License | 5 votes |
def connect_to_server(self): """ Attempts to connect to the TCP server. Raises: Exception (OSException): The connection has failed. """ try: self.tcp.connect((self.address, TCP_PORT)) # self.tcp.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1) # turn on the TCP keepalive # self.tcp.ioctl(socket.SIO_KEEPALIVE_VALS, (1, 1000, 1000)) # configure to send a keepalive packet every second except Exception: self.logger.exception("Unable to connect to host device: IP {0} did not respond.".format(self.address)) sys.exit(1)
Example #14
Source File: pool.py From integrations-core with BSD 3-Clause "New" or "Revised" License | 5 votes |
def _set_keepalive_times(sock): idle_ms = min(_DEFAULT_TCP_IDLE_MS, _MAX_TCP_KEEPIDLE * 1000) interval_ms = min(_DEFAULT_TCP_INTERVAL_MS, _MAX_TCP_KEEPINTVL * 1000) if (idle_ms < _DEFAULT_TCP_IDLE_MS or interval_ms < _DEFAULT_TCP_INTERVAL_MS): sock.ioctl(socket.SIO_KEEPALIVE_VALS, (1, idle_ms, interval_ms))