On win32, sockets apparently can't be used with ReadFile and WriteFile: You need send() and recv() instead. Also, you need to use ioctlsocket() with sockets, not ioctl. [Fixes evbuffer regression tests.]

svn:r448
This commit is contained in:
Nick Mathewson 2007-09-20 19:36:03 +00:00
parent 1e1f77c5b0
commit db43c1e111
2 changed files with 19 additions and 23 deletions

View File

@ -23,4 +23,5 @@ Changes in current version:
o Make autogen.sh script run correctly on systems where /bin/sh isn't bash. (Patch from Trond Norbye, rewritten by Hagne Mahre and then Hannah Schroeter.) o Make autogen.sh script run correctly on systems where /bin/sh isn't bash. (Patch from Trond Norbye, rewritten by Hagne Mahre and then Hannah Schroeter.)
o Skip calling gettime() in timeout_process if we are not in fact waiting for any events. (Patch from Trond Norbye) o Skip calling gettime() in timeout_process if we are not in fact waiting for any events. (Patch from Trond Norbye)
o Make test subdirectory compile under mingw. o Make test subdirectory compile under mingw.
o Fix win32 buffer.c behavior so that it is correct for sockets (which do not like ReadFile and WriteFile).

View File

@ -29,6 +29,11 @@
#include "config.h" #include "config.h"
#endif #endif
#ifdef WIN32
#include <windows.h>
#include <winsock2.h>
#endif
#ifdef HAVE_VASPRINTF #ifdef HAVE_VASPRINTF
/* If we have vasprintf, we need to define this before we include stdio.h. */ /* If we have vasprintf, we need to define this before we include stdio.h. */
#define _GNU_SOURCE #define _GNU_SOURCE
@ -351,12 +356,14 @@ evbuffer_read(struct evbuffer *buf, int fd, int howmuch)
u_char *p; u_char *p;
size_t oldoff = buf->off; size_t oldoff = buf->off;
int n = EVBUFFER_MAX_READ; int n = EVBUFFER_MAX_READ;
#ifdef WIN32
DWORD dwBytesRead;
#endif
#ifdef FIONREAD #if defined(FIONREAD)
#ifdef WIN32
long lng = n;
if (ioctlsocket(fd, FIONREAD, &lng) == -1 || (n=lng) == 0) {
#else
if (ioctl(fd, FIONREAD, &n) == -1 || n == 0) { if (ioctl(fd, FIONREAD, &n) == -1 || n == 0) {
#endif
n = EVBUFFER_MAX_READ; n = EVBUFFER_MAX_READ;
} else if (n > EVBUFFER_MAX_READ && n > howmuch) { } else if (n > EVBUFFER_MAX_READ && n > howmuch) {
/* /*
@ -384,18 +391,14 @@ evbuffer_read(struct evbuffer *buf, int fd, int howmuch)
#ifndef WIN32 #ifndef WIN32
n = read(fd, p, howmuch); n = read(fd, p, howmuch);
#else
//n = ReadFile((HANDLE)fd, p, howmuch, &dwBytesRead, NULL);
n = recv(fd, p, howmuch, 0);
#endif
if (n == -1) if (n == -1)
return (-1); return (-1);
if (n == 0) if (n == 0)
return (0); return (0);
#else
n = ReadFile((HANDLE)fd, p, howmuch, &dwBytesRead, NULL);
if (n == 0)
return (-1);
if (dwBytesRead == 0)
return (0);
n = dwBytesRead;
#endif
buf->off += n; buf->off += n;
@ -410,24 +413,16 @@ int
evbuffer_write(struct evbuffer *buffer, int fd) evbuffer_write(struct evbuffer *buffer, int fd)
{ {
int n; int n;
#ifdef WIN32
DWORD dwBytesWritten;
#endif
#ifndef WIN32 #ifndef WIN32
n = write(fd, buffer->buffer, buffer->off); n = write(fd, buffer->buffer, buffer->off);
#else
n = send(fd, buffer->buffer, buffer->off, 0);
#endif
if (n == -1) if (n == -1)
return (-1); return (-1);
if (n == 0) if (n == 0)
return (0); return (0);
#else
n = WriteFile((HANDLE)fd, buffer->buffer, buffer->off, &dwBytesWritten, NULL);
if (n == 0)
return (-1);
if (dwBytesWritten == 0)
return (0);
n = dwBytesWritten;
#endif
evbuffer_drain(buffer, n); evbuffer_drain(buffer, n);
return (n); return (n);