From 91852564dc7f51ac8f18be600905d4aff4b156de Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Wed, 8 Aug 2018 22:00:48 +0200 Subject: [PATCH] server: Improve named pipe read error handling. Signed-off-by: Jacek Caban Signed-off-by: Alexandre Julliard --- dlls/ntdll/tests/pipe.c | 2 -- server/named_pipe.c | 12 +++++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/dlls/ntdll/tests/pipe.c b/dlls/ntdll/tests/pipe.c index 67141f1f144..a2ef00848ea 100644 --- a/dlls/ntdll/tests/pipe.c +++ b/dlls/ntdll/tests/pipe.c @@ -1338,7 +1338,6 @@ static void test_pipe_state(HANDLE pipe, BOOL is_server, DWORD state) break; } status = NtReadFile(pipe, NULL, NULL, NULL, &io, buf, 1, NULL, NULL); - todo_wine_if(state == FILE_PIPE_DISCONNECTED_STATE && !is_server) ok(status == expected_status, "NtReadFile failed in %s state %u: %x\n", is_server ? "server" : "client", state, status); } @@ -1427,7 +1426,6 @@ static void test_pipe_with_data_state(HANDLE pipe, BOOL is_server, DWORD state) if (state == FILE_PIPE_CLOSING_STATE) expected_status = STATUS_SUCCESS; status = NtReadFile(pipe, NULL, NULL, NULL, &io, buf, 1, NULL, NULL); - todo_wine_if(state == FILE_PIPE_DISCONNECTED_STATE && status != STATUS_PIPE_DISCONNECTED) ok(status == expected_status, "NtReadFile failed in %s state %u: %x\n", is_server ? "server" : "client", state, status); } diff --git a/server/named_pipe.c b/server/named_pipe.c index cb740510c3f..425a369bd81 100644 --- a/server/named_pipe.c +++ b/server/named_pipe.c @@ -798,8 +798,18 @@ static int pipe_end_read( struct fd *fd, struct async *async, file_pos_t pos ) { struct pipe_end *pipe_end = get_fd_user( fd ); - if (!pipe_end->connection && list_empty( &pipe_end->message_queue )) + switch (pipe_end->state) { + case FILE_PIPE_CONNECTED_STATE: + break; + case FILE_PIPE_DISCONNECTED_STATE: + set_error( STATUS_PIPE_DISCONNECTED ); + return 0; + case FILE_PIPE_LISTENING_STATE: + set_error( STATUS_PIPE_LISTENING ); + return 0; + case FILE_PIPE_CLOSING_STATE: + if (!list_empty( &pipe_end->message_queue )) break; set_error( STATUS_PIPE_BROKEN ); return 0; }