From 7038b9ef151c7946a376adff584e002b0eb2b039 Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Wed, 8 Aug 2018 22:00:55 +0200 Subject: [PATCH] server: Improve named pipe write error handling. Signed-off-by: Jacek Caban Signed-off-by: Alexandre Julliard --- dlls/kernel32/tests/pipe.c | 10 +++++----- dlls/ntdll/tests/pipe.c | 1 - server/named_pipe.c | 11 ++++++++++- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/dlls/kernel32/tests/pipe.c b/dlls/kernel32/tests/pipe.c index 7187b3cede1..d724e00c1af 100644 --- a/dlls/kernel32/tests/pipe.c +++ b/dlls/kernel32/tests/pipe.c @@ -1149,7 +1149,7 @@ static DWORD CALLBACK serverThreadMain4(LPVOID arg) SetLastError(ERROR_SUCCESS); success = WriteFile(hnp, buf, readden, &written, &oWrite); err = GetLastError(); - todo_wine_if (!success && err == ERROR_PIPE_NOT_CONNECTED) ok(!success && err == ERROR_NO_DATA, + ok(!success && err == ERROR_NO_DATA, "overlapped WriteFile on disconnected pipe returned %u, err=%i\n", success, err); /* No completion status is queued on immediate error. */ @@ -1605,7 +1605,7 @@ static void test_CloseHandle(void) SetLastError(0xdeadbeef); ret = WriteFile(hfile, testdata, sizeof(testdata), &numbytes, NULL); ok(!ret, "WriteFile unexpectedly succeeded\n"); - todo_wine ok(GetLastError() == ERROR_NO_DATA, "expected ERROR_NO_DATA, got %u\n", GetLastError()); + ok(GetLastError() == ERROR_NO_DATA, "expected ERROR_NO_DATA, got %u\n", GetLastError()); CloseHandle(hfile); @@ -1650,7 +1650,7 @@ static void test_CloseHandle(void) SetLastError(0xdeadbeef); ret = WriteFile(hfile, testdata, sizeof(testdata), &numbytes, NULL); ok(!ret, "WriteFile unexpectedly succeeded\n"); - todo_wine ok(GetLastError() == ERROR_NO_DATA, "expected ERROR_NO_DATA, got %u\n", GetLastError()); + ok(GetLastError() == ERROR_NO_DATA, "expected ERROR_NO_DATA, got %u\n", GetLastError()); CloseHandle(hfile); @@ -1715,7 +1715,7 @@ static void test_CloseHandle(void) SetLastError(0xdeadbeef); ret = WriteFile(hpipe, testdata, sizeof(testdata), &numbytes, NULL); ok(!ret, "WriteFile unexpectedly succeeded\n"); - todo_wine ok(GetLastError() == ERROR_NO_DATA, "expected ERROR_NO_DATA, got %u\n", GetLastError()); + ok(GetLastError() == ERROR_NO_DATA, "expected ERROR_NO_DATA, got %u\n", GetLastError()); CloseHandle(hpipe); @@ -1760,7 +1760,7 @@ static void test_CloseHandle(void) SetLastError(0xdeadbeef); ret = WriteFile(hpipe, testdata, sizeof(testdata), &numbytes, NULL); ok(!ret, "WriteFile unexpectedly succeeded\n"); - todo_wine ok(GetLastError() == ERROR_NO_DATA, "expected ERROR_NO_DATA, got %u\n", GetLastError()); + ok(GetLastError() == ERROR_NO_DATA, "expected ERROR_NO_DATA, got %u\n", GetLastError()); CloseHandle(hpipe); } diff --git a/dlls/ntdll/tests/pipe.c b/dlls/ntdll/tests/pipe.c index a2ef00848ea..d8ccdd1905e 100644 --- a/dlls/ntdll/tests/pipe.c +++ b/dlls/ntdll/tests/pipe.c @@ -1419,7 +1419,6 @@ static void test_pipe_with_data_state(HANDLE pipe, BOOL is_server, DWORD state) break; } status = NtWriteFile(pipe, NULL, NULL, NULL, &io, buf, 1, NULL, NULL); - todo_wine_if(expected_status == STATUS_PIPE_CLOSING) ok(status == expected_status, "NtWriteFile 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 425a369bd81..0806d99985c 100644 --- a/server/named_pipe.c +++ b/server/named_pipe.c @@ -826,10 +826,19 @@ static int pipe_end_write( struct fd *fd, struct async *async, file_pos_t pos ) struct pipe_message *message; struct iosb *iosb; - if (!pipe_end->connection) + 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: + set_error( STATUS_PIPE_CLOSING ); + return 0; } if (!(pipe_end->flags & NAMED_PIPE_MESSAGE_STREAM_WRITE) && !get_req_data_size()) return 1;