Signed-off-by: Brendan Shanks bshanks@codeweavers.com --- v2: Don't leak pipe_message, and correctly handle a nonblocking write larger than the buffer while a read is pending
dlls/kernel32/tests/pipe.c | 22 +++++++++++----------- server/named_pipe.c | 18 +++++++++++++----- 2 files changed, 24 insertions(+), 16 deletions(-)
diff --git a/dlls/kernel32/tests/pipe.c b/dlls/kernel32/tests/pipe.c index 9b544afca7..370073a8a7 100644 --- a/dlls/kernel32/tests/pipe.c +++ b/dlls/kernel32/tests/pipe.c @@ -3941,7 +3941,7 @@ static void test_nowait(void)
/* write one byte larger than the buffer size, should fail */ SetLastError(0xdeadbeef); - todo_wine ok(WriteFile(pipewrite, readbuf, 513, &write, &ol), "WriteFile should succeed\n"); + ok(WriteFile(pipewrite, readbuf, 513, &write, &ol), "WriteFile should succeed\n"); /* WriteFile only documents that 'write < sizeof(readbuf)' for this case, but Windows * doesn't seem to do partial writes ('write == 0' always) */ @@ -3952,27 +3952,27 @@ static void test_nowait(void)
/* start overlapped read, then non-blocking write (smaller than buffer, then bigger than buffer) */ SetLastError(0xdeadbeef); - todo_wine ok(ReadFile(piperead, readbuf, sizeof(readbuf), &read, &ol2) == FALSE, "ReadFile should fail\n"); - todo_wine ok(GetLastError() == ERROR_IO_PENDING, "got %d should be ERROR_IO_PENDING\n", GetLastError()); + ok(ReadFile(piperead, readbuf, sizeof(readbuf), &read, &ol2) == FALSE, "ReadFile should fail\n"); + ok(GetLastError() == ERROR_IO_PENDING, "got %d should be ERROR_IO_PENDING\n", GetLastError()); ok(WriteFile(pipewrite, teststring, sizeof(teststring), &write, &ol), "WriteFile should succeed\n"); ok(write == sizeof(teststring), "got %d, write should be %d\n", write, sizeof(teststring)); ok(GetOverlappedResult(piperead, &ol2, &read, FALSE), "GetOverlappedResult should succeed\n"); - todo_wine ok(read == sizeof(teststring), "got %d, read should be %d\n", write, sizeof(teststring)); + ok(read == sizeof(teststring), "got %d, read should be %d\n", write, sizeof(teststring));
SetLastError(0xdeadbeef); - todo_wine ok(ReadFile(piperead, readbuf, sizeof(readbuf), &read, &ol2) == FALSE, "ReadFile should fail\n"); - todo_wine ok(GetLastError() == ERROR_IO_PENDING, "got %d should be ERROR_IO_PENDING\n", GetLastError()); - todo_wine ok(WriteFile(pipewrite, readbuf, 513, &write, &ol), "WriteFile should succeed\n"); - todo_wine ok(write == 513, "got %d, write should be %d\n", write, 513); + ok(ReadFile(piperead, readbuf, sizeof(readbuf), &read, &ol2) == FALSE, "ReadFile should fail\n"); + ok(GetLastError() == ERROR_IO_PENDING, "got %d should be ERROR_IO_PENDING\n", GetLastError()); + ok(WriteFile(pipewrite, readbuf, 513, &write, &ol), "WriteFile should succeed\n"); + ok(write == 513, "got %d, write should be %d\n", write, 513); ok(GetOverlappedResult(piperead, &ol2, &read, FALSE), "GetOverlappedResult should succeed\n"); - todo_wine ok(read == 513, "got %d, read should be %d\n", write, 513); + ok(read == 513, "got %d, read should be %d\n", write, 513); if (GetOverlappedResult(piperead, &ol2, &read, FALSE) == FALSE) CancelIo(piperead);
/* write the exact buffer size, should succeed */ SetLastError(0xdeadbeef); - todo_wine ok(WriteFile(pipewrite, readbuf, 512, &write, &ol), "WriteFile should succeed\n"); - todo_wine ok(write == 512, "WriteFile should write the whole buffer\n"); + ok(WriteFile(pipewrite, readbuf, 512, &write, &ol), "WriteFile should succeed\n"); + ok(write == 512, "WriteFile should write the whole buffer\n"); if (GetLastError() == ERROR_IO_PENDING) CancelIo(piperead);
diff --git a/server/named_pipe.c b/server/named_pipe.c index 6926712b8c..f3251439b2 100644 --- a/server/named_pipe.c +++ b/server/named_pipe.c @@ -363,7 +363,7 @@ static struct pipe_message *queue_message( struct pipe_end *pipe_end, struct ios return message; }
-static void wake_message( struct pipe_message *message ) +static void wake_message( struct pipe_message *message, data_size_t result ) { struct async *async = message->async;
@@ -371,7 +371,7 @@ static void wake_message( struct pipe_message *message ) if (!async) return;
message->iosb->status = STATUS_SUCCESS; - message->iosb->result = message->iosb->in_size; + message->iosb->result = result; async_terminate( async, message->iosb->result ? STATUS_ALERTED : STATUS_SUCCESS ); release_object( async ); } @@ -749,7 +749,7 @@ static void message_queue_read( struct pipe_end *pipe_end, struct iosb *iosb ) { iosb->out_data = message->iosb->in_data; message->iosb->in_data = NULL; - wake_message( message ); + wake_message( message, message->iosb->in_size ); free_message( message ); } else @@ -773,7 +773,7 @@ static void message_queue_read( struct pipe_end *pipe_end, struct iosb *iosb ) message->read_pos += writing; if (message->read_pos == message->iosb->in_size) { - wake_message(message); + wake_message(message, message->iosb->in_size); free_message(message); } } while (write_pos < iosb->out_size); @@ -836,7 +836,15 @@ static void reselect_write_queue( struct pipe_end *pipe_end ) { avail += message->iosb->in_size - message->read_pos; if (message->async && (avail <= reader->buffer_size || !message->iosb->in_size)) - wake_message( message ); + { + wake_message( message, message->iosb->in_size ); + } + else if (message->async && (pipe_end->flags & NAMED_PIPE_NONBLOCKING_MODE) && + !async_waiting( &reader->read_q )) + { + wake_message( message, 0 ); + free_message( message ); + } } }