summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar snowdrop2004-09-14 15:31:24 +0000
committerGravatar snowdrop2004-09-14 15:31:24 +0000
commit34e3bcee0cf566ad819033300c9f786ebac3f227 (patch)
tree52ce2bdb5e4a80ad56f45540259f83ff654acdae
parent89d265eda17b5172eba32fc4293971581d80eec4 (diff)
downloadcsoap-34e3bcee0cf566ad819033300c9f786ebac3f227.tar.gz
csoap-34e3bcee0cf566ad819033300c9f786ebac3f227.tar.bz2
migrating with mingw
-rw-r--r--nanohttp/nanohttp-common.h6
-rw-r--r--nanohttp/nanohttp-server.c55
-rw-r--r--nanohttp/nanohttp-socket.c3
3 files changed, 56 insertions, 8 deletions
diff --git a/nanohttp/nanohttp-common.h b/nanohttp/nanohttp-common.h
index ef70b0f..455e9ed 100644
--- a/nanohttp/nanohttp-common.h
+++ b/nanohttp/nanohttp-common.h
@@ -1,5 +1,5 @@
/******************************************************************
- * $Id: nanohttp-common.h,v 1.9 2004/09/14 13:23:10 snowdrop Exp $
+ * $Id: nanohttp-common.h,v 1.10 2004/09/14 15:31:24 snowdrop Exp $
*
* CSOAP Project: A http client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -148,7 +148,9 @@ log_level_t log_get_level();
#ifdef WIN32
- #define __FUNCTION__ "***"
+ #ifndef __MINGW32__
+ #define __FUNCTION__ "***"
+ #endif
#endif
#define log_verbose1(a1) log_verbose(__FUNCTION__, a1)
diff --git a/nanohttp/nanohttp-server.c b/nanohttp/nanohttp-server.c
index 9e81a76..8d86b86 100644
--- a/nanohttp/nanohttp-server.c
+++ b/nanohttp/nanohttp-server.c
@@ -1,5 +1,5 @@
/******************************************************************
-* $Id: nanohttp-server.c,v 1.21 2004/09/14 13:23:10 snowdrop Exp $
+* $Id: nanohttp-server.c,v 1.22 2004/09/14 15:31:24 snowdrop Exp $
*
* CSOAP Project: A http client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -457,12 +457,12 @@ void _httpd_register_signal_handler()
FUNCTION: _httpd_wait_for_empty_conn
----------------------------------------------------*/
static
-conndata_t *_httpd_wait_for_empty_conn(int *term_flag)
+conndata_t *_httpd_wait_for_empty_conn()
{
int i;
for (i = 0;; i++)
{
- if (!*term_flag)
+ if (!_httpd_run)
return NULL;
if (i >= _httpd_max_connections)
@@ -510,6 +510,37 @@ void _httpd_start_thread(conndata_t* conn)
/*
* -----------------------------------------------------
+ * FUNCTION: _httpd_select
+ * Returns 0 if success != otherwise
+ * -----------------------------------------------------
+ */
+static
+int _httpd_select(fd_set *pfds)
+{
+ int err;
+ struct timeval timeout;
+
+ timeout.tv_sec = 1;
+ timeout.tv_usec = 0;
+
+ FD_ZERO (pfds);
+ FD_SET (_httpd_socket, pfds);
+
+#ifndef WIN32
+ select (1, pfds, NULL, NULL, &timeout);
+#else
+ if (select (1, pfds, NULL, NULL, &timeout) == SOCKET_ERROR)
+ {
+ err = WSAGetLastError ();
+ log_error1 ("select error");
+ return 1;
+ }
+#endif
+ return 0;
+}
+
+/*
+ * -----------------------------------------------------
* FUNCTION: httpd_run
* -----------------------------------------------------
*/
@@ -519,6 +550,7 @@ httpd_run ()
{
int err;
conndata_t *conn;
+ fd_set fds;
log_verbose1 ("starting run routine");
@@ -546,8 +578,21 @@ httpd_run ()
while (_httpd_run)
{
/* Get an empty connection struct */
- conn = _httpd_wait_for_empty_conn(&_httpd_run);
- if (conn == NULL) break;
+ conn = _httpd_wait_for_empty_conn();
+ if (!_httpd_run) break;
+
+ /* Select file descriptor */
+ if (_httpd_select(&fds))
+ {
+ log_error1("Can not select!");
+ return -1; /* this is hard core! */
+ }
+
+ /* Wait for a socket to accept */
+ while (_httpd_run && (FD_ISSET (_httpd_socket, &fds)));
+
+ if (!_httpd_run)
+ break;
/* Accept a socket */
err = hsocket_accept(_httpd_socket, &(conn->sock));
diff --git a/nanohttp/nanohttp-socket.c b/nanohttp/nanohttp-socket.c
index fc83221..1770a21 100644
--- a/nanohttp/nanohttp-socket.c
+++ b/nanohttp/nanohttp-socket.c
@@ -1,5 +1,5 @@
/******************************************************************
-* $Id: nanohttp-socket.c,v 1.19 2004/09/14 13:25:50 snowdrop Exp $
+* $Id: nanohttp-socket.c,v 1.20 2004/09/14 15:31:24 snowdrop Exp $
*
* CSOAP Project: A http client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -203,6 +203,7 @@ int hsocket_accept(hsocket_t sock, hsocket_t *dest)
#ifdef WIN32
while(1)
{
+ log_debug1("accept()");
sockfd = accept(sock, (struct sockaddr *)&addr, &asize);
if (sockfd == INVALID_SOCKET)
{