mirror of https://github.com/docker/docker-py.git
socket: handle npipe close on Windows (#3056)
Fixes https://github.com/docker/docker-py/issues/3045 Signed-off-by: Nick Santos <nick.santos@docker.com>
This commit is contained in:
parent
bc0a5fbacd
commit
30022984f6
|
|
@ -18,6 +18,11 @@ class SocketError(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
# NpipeSockets have their own error types
|
||||||
|
# pywintypes.error: (109, 'ReadFile', 'The pipe has been ended.')
|
||||||
|
NPIPE_ENDED = 109
|
||||||
|
|
||||||
|
|
||||||
def read(socket, n=4096):
|
def read(socket, n=4096):
|
||||||
"""
|
"""
|
||||||
Reads at most n bytes from socket
|
Reads at most n bytes from socket
|
||||||
|
|
@ -37,6 +42,15 @@ def read(socket, n=4096):
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
if e.errno not in recoverable_errors:
|
if e.errno not in recoverable_errors:
|
||||||
raise
|
raise
|
||||||
|
except Exception as e:
|
||||||
|
is_pipe_ended = (isinstance(socket, NpipeSocket) and
|
||||||
|
len(e.args) > 0 and
|
||||||
|
e.args[0] == NPIPE_ENDED)
|
||||||
|
if is_pipe_ended:
|
||||||
|
# npipes don't support duplex sockets, so we interpret
|
||||||
|
# a PIPE_ENDED error as a close operation (0-length read).
|
||||||
|
return 0
|
||||||
|
raise
|
||||||
|
|
||||||
|
|
||||||
def read_exactly(socket, n):
|
def read_exactly(socket, n):
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue