Index: buffer.c
===================================================================
--- buffer.c	(revision 703)
+++ buffer.c	(working copy)
@@ -29,6 +29,10 @@
 #include "config.h"
 #endif
 
+#ifdef WIN32
+#include "WIN32-Code/config.h"
+#endif
+
 #ifdef HAVE_VASPRINTF
 /* If we have vasprintf, we need to define this before we include stdio.h. */
 #define _GNU_SOURCE
@@ -353,6 +357,8 @@
 	int n = EVBUFFER_MAX_READ;
 #ifdef WIN32
 	DWORD dwBytesRead;
+	DWORD flags = 0;
+	WSABUF b;
 #endif
 
 #ifdef FIONREAD
@@ -394,9 +400,18 @@
 	if (n == 0)
 		return (0);
 #else
-	n = ReadFile((HANDLE)fd, p, howmuch, &dwBytesRead, NULL);
-	if (n == 0)
+//	n = ReadFile((HANDLE)fd, p, howmuch, &dwBytesRead, NULL);
+	b.buf = p;
+	b.len = howmuch;
+
+	n = WSARecv((SOCKET) fd, &b, 1, &dwBytesRead, &flags, 0, 0);
+	if (n == -1)
+	{
+		DWORD err = WSAGetLastError();
+		if (err == ERROR_NO_DATA)
+			return (0);
 		return (-1);
+	}
 	if (dwBytesRead == 0)
 		return (0);
 	n = dwBytesRead;
@@ -417,6 +432,8 @@
 	int n;
 #ifdef WIN32
 	DWORD dwBytesWritten;
+	DWORD flags = 0;
+	WSABUF b;
 #endif
 
 #ifndef WIN32
@@ -426,8 +443,11 @@
 	if (n == 0)
 		return (0);
 #else
-	n = WriteFile((HANDLE)fd, buffer->buffer, buffer->off, &dwBytesWritten, NULL);
-	if (n == 0)
+//	n = WriteFile((HANDLE)fd, buffer->buffer, buffer->off, &dwBytesWritten, NULL);
+	b.buf = buffer->buffer;
+	b.len = buffer->off;
+	n = WSASend((SOCKET) fd, &b, 1, &dwBytesWritten, flags, 0, 0);
+	if (n == -1)
 		return (-1);
 	if (dwBytesWritten == 0)
 		return (0);
Index: evbuffer.c
===================================================================
--- evbuffer.c	(revision 703)
+++ evbuffer.c	(working copy)
@@ -31,6 +31,10 @@
 #include "config.h"
 #endif
 
+#ifdef WIN32
+#include "WIN32-Code/config.h"
+#endif
+
 #ifdef HAVE_SYS_TIME_H
 #include <sys/time.h>
 #endif
Index: event.c
===================================================================
--- event.c	(revision 703)
+++ event.c	(working copy)
@@ -29,6 +29,7 @@
 #endif
 
 #ifdef WIN32
+#include "WIN32-Code/config.h"
 #define WIN32_LEAN_AND_MEAN
 #include <windows.h>
 #undef WIN32_LEAN_AND_MEAN
Index: http-internal.h
===================================================================
--- http-internal.h	(revision 703)
+++ http-internal.h	(working copy)
@@ -10,6 +10,13 @@
 #ifndef _HTTP_H_
 #define _HTTP_H_
 
+#ifdef WIN32
+#include <windows.h>
+#include <winsock2.h>
+typedef int socklen_t;
+
+#endif
+
 #define HTTP_CONNECT_TIMEOUT	45
 #define HTTP_WRITE_TIMEOUT	50
 #define HTTP_READ_TIMEOUT	50
Index: http.c
===================================================================
--- http.c	(revision 703)
+++ http.c	(working copy)
@@ -25,13 +25,19 @@
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+#ifndef WIN32
 #include <sys/param.h>
+#endif
 #include <sys/types.h>
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
 
+#ifdef WIN32
+#include "WIN32-Code/config.h"
+#endif
+
 #ifdef HAVE_SYS_TIME_H
 #include <sys/time.h>
 #endif
@@ -54,6 +60,11 @@
 #include <netdb.h>
 #endif
 
+#ifdef WIN32
+#include <WinSock2.h>
+#include <ws2tcpip.h>
+#endif
+
 #include <assert.h>
 #include <ctype.h>
 #include <errno.h>
@@ -62,10 +73,10 @@
 #include <string.h>
 #ifndef WIN32
 #include <syslog.h>
+#include <unistd.h>
 #endif
 #include <signal.h>
 #include <time.h>
-#include <unistd.h>
 #include <fcntl.h>
 
 #undef timeout_pending
@@ -817,7 +828,11 @@
 		event_del(&evcon->ev);
 	
 	if (evcon->fd != -1)
+#ifdef WIN32
+		closesocket((SOCKET) evcon->fd);
+#else
 		close(evcon->fd);
+#endif
 
 	if (evcon->address != NULL)
 		free(evcon->address);
@@ -863,8 +878,11 @@
 		/* inform interested parties about connection close */
 		if (evcon->state == EVCON_CONNECTED && evcon->closecb != NULL)
 			(*evcon->closecb)(evcon, evcon->closecb_arg);
-
+#ifdef WIN32
+		closesocket((SOCKET) evcon->fd);
+#else
 		close(evcon->fd);
+#endif
 		evcon->fd = -1;
 	}
 	evcon->state = EVCON_DISCONNECTED;
@@ -1982,7 +2000,11 @@
 
 	/* Remove the accepting part */
 	event_del(&http->bind_ev);
+#ifdef WIN32
+	closesocket((SOCKET) fd);
+#else
 	close(fd);
+#endif
 
 	while ((evcon = TAILQ_FIRST(&http->connections)) != NULL) {
 		/* evhttp_connection_free removes the connection */
@@ -2261,7 +2283,11 @@
 	if ((ni_result = getnameinfo(sa, salen,
 		ntop, sizeof(ntop), strport, sizeof(strport),
 		NI_NUMERICHOST|NI_NUMERICSERV)) != 0) {
-		if (ni_result == EAI_SYSTEM)
+#ifndef WIN32
+			if (ni_result == EAI_SYSTEM)
+#else
+			if ( ni_result == EAI_FAIL )
+#endif
 			event_err(1, "getnameinfo failed");
 		else
 			event_errx(1, "getnameinfo failed: %s", gai_strerror(ni_result));
@@ -2280,7 +2306,12 @@
 make_socket_ai(int should_bind, struct addrinfo *ai)
 {
         struct linger linger;
-        int fd, on = 1, r;
+#ifndef WIN32
+        int fd;
+#else
+	SOCKET fd;
+#endif
+	int on = 1, r;
 	int serrno;
 
         /* Create listen socket */
@@ -2328,7 +2359,11 @@
 
  out:
 	serrno = errno;
+#ifndef WIN32
 	close(fd);
+#else
+	closesocket(fd);
+#endif
 	errno = serrno;
 	return (-1);
 }
@@ -2348,7 +2383,11 @@
         ai.ai_flags = should_bind ? AI_PASSIVE : 0;
         snprintf(strport, sizeof (strport), "%d", port);
         if ((ai_result = getaddrinfo(address, strport, &ai, &aitop)) != 0) {
+#ifndef WIN32
                 if ( ai_result == EAI_SYSTEM )
+#else
+                if ( ai_result == EAI_FAIL )
+#endif
                         event_warn("getaddrinfo");
                 else
                         event_warnx("getaddrinfo: %s", gai_strerror(ai_result));
Index: log.c
===================================================================
--- log.c	(revision 703)
+++ log.c	(working copy)
@@ -42,6 +42,10 @@
 #endif
 
 #ifdef WIN32
+#include "WIN32-Code/config.h"
+#endif
+
+#ifdef WIN32
 #define WIN32_LEAN_AND_MEAN
 #include <windows.h>
 #undef WIN32_LEAN_AND_MEAN
Index: strlcpy.c
===================================================================
--- strlcpy.c	(revision 703)
+++ strlcpy.c	(working copy)
@@ -37,6 +37,10 @@
 #include "config.h"
 #endif /* HAVE_CONFIG_H */
 
+#ifdef WIN32
+#include "WIN32-Code/config.h"
+#endif
+
 #ifndef HAVE_STRLCPY
 #include "strlcpy-internal.h"
 
Index: WIN32-Code/config.h
===================================================================
--- WIN32-Code/config.h	(revision 703)
+++ WIN32-Code/config.h	(working copy)
@@ -196,6 +196,10 @@
 /* Define if you can safely include both <sys/time.h> and <time.h>. */
 #undef TIME_WITH_SYS_TIME
 
+#define HAVE_GETADDRINFO
+
+#define HAVE_GETNAMEINFO
+
 /* Version number of package */
 #define VERSION "1.3e"
 
@@ -232,3 +236,7 @@
 
 /* Define to __FUNCTION__ or __file__ if your compiler doesn't have __func__ */
 #define __func__ __FUNCTION__
+
+#define snprintf _snprintf
+#define strcasecmp _stricmp
+#define strncasecmp _strnicmp
Index: WIN32-Code/misc.c
===================================================================
--- WIN32-Code/misc.c	(revision 703)
+++ WIN32-Code/misc.c	(working copy)
@@ -4,6 +4,10 @@
 #include <sys/timeb.h>
 #include <time.h>
 
+#ifdef WIN32
+#include "WIN32-Code/config.h"
+#endif
+
 #ifdef __GNUC__
 /*our prototypes for timeval and timezone are in here, just in case the above
   headers don't have them*/
Index: WIN32-Prj/libevent.vcproj
===================================================================
--- WIN32-Prj/libevent.vcproj	(revision 703)
+++ WIN32-Prj/libevent.vcproj	(working copy)
@@ -202,6 +202,10 @@
 				</FileConfiguration>
 			</File>
 			<File
+				RelativePath="..\http.c"
+				>
+			</File>
+			<File
 				RelativePath="..\log.c"
 				>
 				<FileConfiguration
