[Wine-patches] ws2_32: Use a little timeout in non-blocking mode (eterbug #4399).
Alexander Morozov
amorozov на etersoft.ru
Чт Фев 25 14:30:49 MSK 2010
----------- следующая часть -----------
From 58782ecda1163634de2d27737e0b848525cc80f1 Mon Sep 17 00:00:00 2001
From: Alexander Morozov <amorozov на etersoft.ru>
Date: Thu, 25 Feb 2010 13:03:18 +0300
Subject: [PATCH] ws2_32: Use a little timeout in non-blocking mode (eterbug #4399).
---
dlls/ws2_32/socket.c | 78 ++++++++++++++++++++++---------------------------
1 files changed, 35 insertions(+), 43 deletions(-)
diff --git a/dlls/ws2_32/socket.c b/dlls/ws2_32/socket.c
index c9d9a4e..074136e 100644
--- a/dlls/ws2_32/socket.c
+++ b/dlls/ws2_32/socket.c
@@ -2756,6 +2756,7 @@ INT WINAPI WSASendTo( SOCKET s, LPWSABUF lpBuffers, DWORD dwBufferCount,
int n, fd, err;
struct ws2_async *wsa;
int totalLength = 0;
+ DWORD timeout_start;
ULONG_PTR cvalue = (lpOverlapped && ((ULONG_PTR)lpOverlapped->hEvent & 1) == 0) ? (ULONG_PTR)lpOverlapped : 0;
TRACE("socket %04lx, wsabuf %p, nbufs %d, flags %d, to %p, tolen %d, ovl %p, func %p\n",
@@ -2851,62 +2852,53 @@ INT WINAPI WSASendTo( SOCKET s, LPWSABUF lpBuffers, DWORD dwBufferCount,
return 0;
}
- if ( _is_blocking(s) )
+ timeout_start = GetTickCount();
+ *lpNumberOfBytesSent = 0;
+
+ while (wsa->first_iovec < dwBufferCount)
{
- /* On a blocking non-overlapped stream socket,
- * sending blocks until the entire buffer is sent. */
- DWORD timeout_start = GetTickCount();
+ struct pollfd pfd;
+ int timeout = 10;
- *lpNumberOfBytesSent = 0;
+ if ( _is_blocking(s) )
+ timeout = GET_SNDTIMEO(fd);
- while (wsa->first_iovec < dwBufferCount)
+ if (n >= 0)
{
- struct pollfd pfd;
- int timeout = GET_SNDTIMEO(fd);
-
- if (n >= 0)
- {
- *lpNumberOfBytesSent += n;
- while (wsa->first_iovec < dwBufferCount && wsa->iovec[wsa->first_iovec].iov_len <= n)
- n -= wsa->iovec[wsa->first_iovec++].iov_len;
- if (wsa->first_iovec >= dwBufferCount) break;
- wsa->iovec[wsa->first_iovec].iov_base = (char*)wsa->iovec[wsa->first_iovec].iov_base + n;
- wsa->iovec[wsa->first_iovec].iov_len -= n;
- }
+ *lpNumberOfBytesSent += n;
+ while (wsa->first_iovec < dwBufferCount && wsa->iovec[wsa->first_iovec].iov_len <= n)
+ n -= wsa->iovec[wsa->first_iovec++].iov_len;
+ if (wsa->first_iovec >= dwBufferCount) break;
+ wsa->iovec[wsa->first_iovec].iov_base = (char*)wsa->iovec[wsa->first_iovec].iov_base + n;
+ wsa->iovec[wsa->first_iovec].iov_len -= n;
+ }
- if (timeout != -1)
- {
- timeout -= GetTickCount() - timeout_start;
- if (timeout < 0) timeout = 0;
- }
+ if (timeout != -1)
+ {
+ timeout -= GetTickCount() - timeout_start;
+ if (timeout < 0) timeout = 0;
+ }
- pfd.fd = fd;
- pfd.events = POLLOUT;
+ pfd.fd = fd;
+ pfd.events = POLLOUT;
- if (!timeout || !poll( &pfd, 1, timeout ))
- {
- err = WSAETIMEDOUT;
- goto error; /* msdn says a timeout in send is fatal */
- }
-
- n = WS2_send( fd, wsa );
- if (n == -1 && errno != EAGAIN && errno != EINTR)
+ if (!timeout || !poll( &pfd, 1, timeout ))
+ {
+ if ( !_is_blocking(s) )
{
- err = wsaErrno();
- goto error;
+ _enable_event( SOCKET2HANDLE(s), FD_WRITE, 0, 0 );
+ err = WSAEWOULDBLOCK;
}
+ else err = WSAETIMEDOUT;
+ goto error; /* msdn says a timeout in send is fatal */
}
- }
- else /* non-blocking */
- {
- if (n < totalLength)
- _enable_event(SOCKET2HANDLE(s), FD_WRITE, 0, 0);
- if (n == -1)
+
+ n = WS2_send( fd, wsa );
+ if (n == -1 && errno != EAGAIN && errno != EINTR)
{
- err = WSAEWOULDBLOCK;
+ err = wsaErrno();
goto error;
}
- *lpNumberOfBytesSent = n;
}
TRACE(" -> %i bytes\n", *lpNumberOfBytesSent);
--
1.6.5.8
Подробная информация о списке рассылки Wine-patches