Enable (and debug) WSARecv for evbuffer iovec-like reads.

The two things we were missing: the flags parameter is not optional, and an error can actually indicate a close.

svn:r1100
This commit is contained in:
Nick Mathewson 2009-02-03 05:22:57 +00:00
parent ea11f8195f
commit cc049bfc30

View File

@ -1049,7 +1049,7 @@ _evbuffer_expand_fast(struct evbuffer *buf, size_t datlen)
* Reads data from a file descriptor into a buffer. * Reads data from a file descriptor into a buffer.
*/ */
#if defined(_EVENT_HAVE_SYS_UIO_H) #if defined(_EVENT_HAVE_SYS_UIO_H) || defined(WIN32)
#define USE_IOVEC_IMPL #define USE_IOVEC_IMPL
#endif #endif
@ -1153,9 +1153,15 @@ evbuffer_read(struct evbuffer *buf, evutil_socket_t fd, int howmuch)
#ifdef WIN32 #ifdef WIN32
{ {
DWORD bytesRead; DWORD bytesRead;
if (WSARecv(fd, vecs, nvecs, &bytesRead, 0, NULL, NULL)) DWORD flags=0;
n = -1; if (WSARecv(fd, vecs, nvecs, &bytesRead, &flags, NULL, NULL)) {
else /* The read failed. It might be a close,
* or it might be an error. */
if (WSAGetLastError() == WSAECONNABORTED)
n = 0;
else
n = -1;
} else
n = bytesRead; n = bytesRead;
} }
#else #else
@ -1239,8 +1245,8 @@ ssize_t howmuch)
} }
#ifdef WIN32 #ifdef WIN32
{ {
DWORD byteSent; DWORD bytesSent;
if (WSASend(fd, buffers, i, &bytesSent, 0, NULL, NULL)) if (WSASend(fd, iov, i, &bytesSent, 0, NULL, NULL))
n = -1; n = -1;
else else
n = bytesSent; n = bytesSent;