File tree Expand file tree Collapse file tree 1 file changed +9
-3
lines changed Expand file tree Collapse file tree 1 file changed +9
-3
lines changed Original file line number Diff line number Diff line change 11from __future__ import annotations
22
3+ import socket
34from json import JSONDecodeError
4- from socket import IPPROTO_TCP , SO_KEEPALIVE , SOL_SOCKET , TCP_KEEPIDLE
55from types import TracebackType
66from typing import Callable , List , Optional , Type
77
@@ -157,11 +157,17 @@ async def connect_tcp(
157157 )
158158 # Enable keepalive
159159 stream .get_extra_info ("socket" ).setsockopt (
160- SOL_SOCKET , SO_KEEPALIVE , KEEPALIVE_FLAG
160+ socket . SOL_SOCKET , socket . SO_KEEPALIVE , KEEPALIVE_FLAG
161161 )
162+ # MacOS does not have TCP_KEEPIDLE
163+ if hasattr (socket , "TCP_KEEPIDLE" ):
164+ keepidle = socket .TCP_KEEPIDLE
165+ else :
166+ keepidle = 0x10 # TCP_KEEPALIVE on mac
167+
162168 # Set keepalive to 60 seconds
163169 stream .get_extra_info ("socket" ).setsockopt (
164- IPPROTO_TCP , TCP_KEEPIDLE , KEEPIDLE_RATE
170+ socket . IPPROTO_TCP , keepidle , KEEPIDLE_RATE
165171 )
166172 return stream
167173
You can’t perform that action at this time.
0 commit comments