summaryrefslogtreecommitdiffstats
path: root/nanohttp
diff options
context:
space:
mode:
Diffstat (limited to 'nanohttp')
-rw-r--r--nanohttp/nanohttp-server.c24
-rw-r--r--nanohttp/nanohttp-socket.c10
-rw-r--r--nanohttp/nanohttp-socket.h8
3 files changed, 36 insertions, 6 deletions
diff --git a/nanohttp/nanohttp-server.c b/nanohttp/nanohttp-server.c
index 661c958..907d80d 100644
--- a/nanohttp/nanohttp-server.c
+++ b/nanohttp/nanohttp-server.c
@@ -1,5 +1,5 @@
/******************************************************************
-* $Id: nanohttp-server.c,v 1.57 2006/04/26 17:48:30 mrcsys Exp $
+* $Id: nanohttp-server.c,v 1.58 2006/05/01 17:51:50 mrcsys Exp $
*
* CSOAP Project: A http client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -116,7 +116,6 @@ static hservice_t *_httpd_services_head = NULL;
static hservice_t *_httpd_services_tail = NULL;
static conndata_t *_httpd_connection;
-static pthread_mutex_t _httpd_connection_lock;
static int _httpd_enable_service_list = 0;
static int _httpd_enable_statistics = 0;
@@ -125,11 +124,14 @@ static int _httpd_enable_statistics = 0;
static DWORD _httpd_terminate_signal = CTRL_C_EVENT;
static int _httpd_max_idle = 120;
static void WSAReaper(void *x);
+HANDLE _httpd_connection_lock;
+LPCTSTR _httpd_connection_lock_str;
#define strncasecmp(s1, s2, num) strncmp(s1, s2, num)
#define snprintf(buffer, num, s1, s2) sprintf(buffer, s1,s2)
#else
static int _httpd_terminate_signal = SIGINT;
static sigset_t thrsigset;
+static pthread_mutex_t _httpd_connection_lock;
#endif
static void
@@ -168,7 +170,11 @@ _httpd_connection_slots_init(void)
{
int i;
+#ifdef WIN32
+ _httpd_connection_lock = CreateMutex( NULL, TRUE, _httpd_connection_lock_str );
+#else
pthread_mutex_init(&_httpd_connection_lock, NULL);
+#endif
_httpd_connection = calloc(_httpd_max_connections, sizeof(conndata_t));
for (i = 0; i < _httpd_max_connections; i++)
hsocket_init(&(_httpd_connection[i].sock));
@@ -879,13 +885,21 @@ _httpd_wait_for_empty_conn(void)
{
int i;
+#ifdef WIN32
+ WaitForSingleObject(_httpd_connection_lock, INFINITE);
+#else
pthread_mutex_lock(&_httpd_connection_lock);
+#endif
for (i = 0;; i++)
{
if (!_httpd_run)
{
+#ifdef WIN32
+ ReleaseMutex(_httpd_connection_lock);
+#else
pthread_mutex_unlock(&_httpd_connection_lock);
+#endif
return NULL;
}
@@ -900,7 +914,11 @@ _httpd_wait_for_empty_conn(void)
break;
}
}
- pthread_mutex_unlock(&_httpd_connection_lock);
+#ifdef WIN32
+ ReleaseMutex(_httpd_connection_lock);
+#else
+ pthread_mutex_unlock(&_httpd_connection_lock);
+#endif
return &_httpd_connection[i];
}
diff --git a/nanohttp/nanohttp-socket.c b/nanohttp/nanohttp-socket.c
index 84ee578..7ce9a25 100644
--- a/nanohttp/nanohttp-socket.c
+++ b/nanohttp/nanohttp-socket.c
@@ -1,5 +1,5 @@
/******************************************************************
-* $Id: nanohttp-socket.c,v 1.59 2006/04/26 17:48:29 mrcsys Exp $
+* $Id: nanohttp-socket.c,v 1.60 2006/05/01 17:51:50 mrcsys Exp $
*
* CSOAP Project: A http client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -70,6 +70,8 @@
#include <winsock2.h>
#include <process.h>
+#define inline
+
#ifndef __MINGW32__
typedef int ssize_t;
#endif
@@ -253,7 +255,7 @@ hsocket_bind(hsocket_t * dsock, int port)
static herror_t
_hsocket_sys_accept(hsocket_t * sock, hsocket_t * dest)
{
- socklen_t asize;
+ int asize;
hsocket_t sockfd;
asize = sizeof(struct sockaddr_in);
@@ -452,7 +454,11 @@ hsocket_select_read(int sock, char *buf, size_t len)
log_verbose2("Socket %d timeout", sock);
return -1;
}
+#ifdef WIN32
+ return recv(sock, buf, len, 0);
+#else
return read(sock, buf, len);
+#endif
}
herror_t
diff --git a/nanohttp/nanohttp-socket.h b/nanohttp/nanohttp-socket.h
index fd05040..5c1554d 100644
--- a/nanohttp/nanohttp-socket.h
+++ b/nanohttp/nanohttp-socket.h
@@ -1,5 +1,5 @@
/******************************************************************
- * $Id: nanohttp-socket.h,v 1.27 2006/04/26 17:48:30 mrcsys Exp $
+ * $Id: nanohttp-socket.h,v 1.28 2006/05/01 17:51:50 mrcsys Exp $
*
* CSOAP Project: A http client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -25,8 +25,14 @@
#define NANO_HTTP_SOCKET_H
#include <sys/types.h>
+
+#ifdef HAVE_SOCKET_H
#include <sys/socket.h>
+#endif
+
+#ifdef HAVE_NETINET_IN_H
#include <netinet/in.h>
+#endif
#include <time.h>