Alexandre Julliard : ntdll: Use send(2) instead of write(2)
for zero-byte writes to sockets.
Alexandre Julliard
julliard at wine.codeweavers.com
Mon Apr 9 07:36:03 CDT 2007
Module: wine
Branch: master
Commit: c915215ba6a7bae5d4f850e2c67f29c81df9a1a9
URL: http://source.winehq.org/git/wine.git/?a=commit;h=c915215ba6a7bae5d4f850e2c67f29c81df9a1a9
Author: Alexandre Julliard <julliard at winehq.org>
Date: Mon Apr 9 12:21:24 2007 +0200
ntdll: Use send(2) instead of write(2) for zero-byte writes to sockets.
---
dlls/kernel32/tests/mailslot.c | 2 +-
dlls/ntdll/file.c | 17 ++++++++++++++---
2 files changed, 15 insertions(+), 4 deletions(-)
diff --git a/dlls/kernel32/tests/mailslot.c b/dlls/kernel32/tests/mailslot.c
index 6eb8d8a..995f144 100644
--- a/dlls/kernel32/tests/mailslot.c
+++ b/dlls/kernel32/tests/mailslot.c
@@ -258,8 +258,8 @@ static int mailslot_test(void)
dwNext = dwMsgCount = 0;
ok( GetMailslotInfo( hSlot, NULL, &dwNext, &dwMsgCount, NULL ),
"getmailslotinfo failed\n");
- todo_wine {
ok( dwNext == 0, "dwNext incorrect\n");
+ todo_wine {
ok( dwMsgCount == 1, "dwMsgCount incorrect\n");
}
diff --git a/dlls/ntdll/file.c b/dlls/ntdll/file.c
index 65710c5..0a7eccb 100644
--- a/dlls/ntdll/file.c
+++ b/dlls/ntdll/file.c
@@ -668,6 +668,7 @@ static void WINAPI FILE_AsyncWriteService(void *ovp, IO_STATUS_BLOCK *iosb, ULON
{
async_fileio *fileio = (async_fileio *) ovp;
int result, fd, needs_close;
+ enum server_fd_type type;
TRACE("(%p %p 0x%x)\n",iosb, fileio->buffer, status);
@@ -676,12 +677,16 @@ static void WINAPI FILE_AsyncWriteService(void *ovp, IO_STATUS_BLOCK *iosb, ULON
case STATUS_ALERTED:
/* write some data (non-blocking) */
if ((status = server_get_unix_fd( fileio->handle, FILE_WRITE_DATA, &fd,
- &needs_close, NULL, NULL )))
+ &needs_close, &type, NULL )))
{
fileio_terminate(fileio, iosb, status);
break;
}
- result = write(fd, &fileio->buffer[fileio->already], fileio->count - fileio->already);
+ if (!fileio->count && (type == FD_TYPE_MAILSLOT || type == FD_TYPE_PIPE || type == FD_TYPE_SOCKET))
+ result = send( fd, fileio->buffer, 0, 0 );
+ else
+ result = write( fd, &fileio->buffer[fileio->already], fileio->count - fileio->already );
+
if (needs_close) close( fd );
if (result < 0)
@@ -772,7 +777,13 @@ NTSTATUS WINAPI NtWriteFile(HANDLE hFile, HANDLE hEvent,
for (;;)
{
- if ((result = write( unix_handle, (const char *)buffer + total, length - total )) >= 0)
+ /* zero-length writes on sockets may not work with plain write(2) */
+ if (!length && (type == FD_TYPE_MAILSLOT || type == FD_TYPE_PIPE || type == FD_TYPE_SOCKET))
+ result = send( unix_handle, buffer, 0, 0 );
+ else
+ result = write( unix_handle, (const char *)buffer + total, length - total );
+
+ if (result >= 0)
{
total += result;
if (total == length)
More information about the wine-cvs
mailing list