File tree Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,11 @@ class SocketError(Exception):
1818 pass
1919
2020
21+ # NpipeSockets have their own error types
22+ # pywintypes.error: (109, 'ReadFile', 'The pipe has been ended.')
23+ NPIPE_ENDED = 109
24+
25+
2126def read (socket , n = 4096 ):
2227 """
2328 Reads at most n bytes from socket
@@ -37,6 +42,15 @@ def read(socket, n=4096):
3742 except OSError as e :
3843 if e .errno not in recoverable_errors :
3944 raise
45+ except Exception as e :
46+ is_pipe_ended = (isinstance (socket , NpipeSocket ) and
47+ len (e .args ) > 0 and
48+ e .args [0 ] == NPIPE_ENDED )
49+ if is_pipe_ended :
50+ # npipes don't support duplex sockets, so we interpret
51+ # a PIPE_ENDED error as a close operation (0-length read).
52+ return 0
53+ raise
4054
4155
4256def read_exactly (socket , n ):
You can’t perform that action at this time.
0 commit comments