mirror of
https://github.com/cuberite/libevent.git
synced 2025-09-12 22:10:12 -04:00
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:
parent
1e1f77c5b0
commit
db43c1e111
@ -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 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 Fix win32 buffer.c behavior so that it is correct for sockets (which do not like ReadFile and WriteFile).
|
||||
|
||||
|
41
buffer.c
41
buffer.c
@ -29,6 +29,11 @@
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#ifdef WIN32
|
||||
#include <windows.h>
|
||||
#include <winsock2.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_VASPRINTF
|
||||
/* If we have vasprintf, we need to define this before we include stdio.h. */
|
||||
#define _GNU_SOURCE
|
||||
@ -351,12 +356,14 @@ evbuffer_read(struct evbuffer *buf, int fd, int howmuch)
|
||||
u_char *p;
|
||||
size_t oldoff = buf->off;
|
||||
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) {
|
||||
#endif
|
||||
n = EVBUFFER_MAX_READ;
|
||||
} else if (n > EVBUFFER_MAX_READ && n > howmuch) {
|
||||
/*
|
||||
@ -384,18 +391,14 @@ evbuffer_read(struct evbuffer *buf, int fd, int howmuch)
|
||||
|
||||
#ifndef WIN32
|
||||
n = read(fd, p, howmuch);
|
||||
#else
|
||||
//n = ReadFile((HANDLE)fd, p, howmuch, &dwBytesRead, NULL);
|
||||
n = recv(fd, p, howmuch, 0);
|
||||
#endif
|
||||
if (n == -1)
|
||||
return (-1);
|
||||
if (n == 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;
|
||||
|
||||
@ -410,24 +413,16 @@ int
|
||||
evbuffer_write(struct evbuffer *buffer, int fd)
|
||||
{
|
||||
int n;
|
||||
#ifdef WIN32
|
||||
DWORD dwBytesWritten;
|
||||
#endif
|
||||
|
||||
#ifndef WIN32
|
||||
n = write(fd, buffer->buffer, buffer->off);
|
||||
#else
|
||||
n = send(fd, buffer->buffer, buffer->off, 0);
|
||||
#endif
|
||||
if (n == -1)
|
||||
return (-1);
|
||||
if (n == 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);
|
||||
|
||||
return (n);
|
||||
|
Loading…
x
Reference in New Issue
Block a user