Module: wine Branch: master Commit: 7038b9ef151c7946a376adff584e002b0eb2b039 URL: https://source.winehq.org/git/wine.git/?a=commit;h=7038b9ef151c7946a376adff5...
Author: Jacek Caban jacek@codeweavers.com Date: Wed Aug 8 22:00:55 2018 +0200
server: Improve named pipe write error handling.
Signed-off-by: Jacek Caban jacek@codeweavers.com Signed-off-by: Alexandre Julliard julliard@winehq.org
---
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 7187b3c..d724e00 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 a2ef008..d8ccdd1 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 425a369..0806d99 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;