ws2_32: Fix up iovecs after transmission in WS2_send instead of WS2_sendto.

This commit is contained in:
Mike Kaplinskiy 2011-01-24 00:19:12 -05:00 committed by Alexandre Julliard
parent e6fee3596d
commit 388398bd05

View File

@ -1725,6 +1725,7 @@ static int WS2_send( int fd, struct ws2_async *wsa )
{ {
struct msghdr hdr; struct msghdr hdr;
union generic_unix_sockaddr unix_addr; union generic_unix_sockaddr unix_addr;
int n, ret;
hdr.msg_name = NULL; hdr.msg_name = NULL;
hdr.msg_namelen = 0; hdr.msg_namelen = 0;
@ -1768,7 +1769,19 @@ static int WS2_send( int fd, struct ws2_async *wsa )
hdr.msg_flags = 0; hdr.msg_flags = 0;
#endif #endif
return sendmsg(fd, &hdr, wsa->flags); ret = sendmsg(fd, &hdr, wsa->flags);
if (ret >= 0)
{
n = ret;
while (wsa->first_iovec < wsa->n_iovecs && wsa->iovec[wsa->first_iovec].iov_len <= n)
n -= wsa->iovec[wsa->first_iovec++].iov_len;
if (wsa->first_iovec < wsa->n_iovecs)
{
wsa->iovec[wsa->first_iovec].iov_base = (char*)wsa->iovec[wsa->first_iovec].iov_base + n;
wsa->iovec[wsa->first_iovec].iov_len -= n;
}
}
return ret;
} }
/*********************************************************************** /***********************************************************************
@ -3942,23 +3955,13 @@ static int WS2_sendto( SOCKET s, LPWSABUF lpBuffers, DWORD dwBufferCount,
* sending blocks until the entire buffer is sent. */ * sending blocks until the entire buffer is sent. */
DWORD timeout_start = GetTickCount(); DWORD timeout_start = GetTickCount();
*lpNumberOfBytesSent = 0; *lpNumberOfBytesSent = n == -1 ? 0 : n;
while (wsa->first_iovec < dwBufferCount) while (wsa->first_iovec < wsa->n_iovecs)
{ {
struct pollfd pfd; struct pollfd pfd;
int timeout = GET_SNDTIMEO(fd); 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;
}
if (timeout != -1) if (timeout != -1)
{ {
timeout -= GetTickCount() - timeout_start; timeout -= GetTickCount() - timeout_start;
@ -3980,6 +3983,9 @@ static int WS2_sendto( SOCKET s, LPWSABUF lpBuffers, DWORD dwBufferCount,
err = wsaErrno(); err = wsaErrno();
goto error; goto error;
} }
if (n >= 0)
*lpNumberOfBytesSent += n;
} }
} }
else /* non-blocking */ else /* non-blocking */