diff options
Diffstat (limited to 'nanohttp')
-rw-r--r-- | nanohttp/nanohttp-client.c | 32 | ||||
-rw-r--r-- | nanohttp/nanohttp-client.h | 5 | ||||
-rw-r--r-- | nanohttp/nanohttp-server.c | 23 | ||||
-rw-r--r-- | nanohttp/nanohttp-socket.c | 47 | ||||
-rw-r--r-- | nanohttp/nanohttp-socket.h | 6 |
5 files changed, 63 insertions, 50 deletions
diff --git a/nanohttp/nanohttp-client.c b/nanohttp/nanohttp-client.c index 59d0cd0..22571c6 100644 --- a/nanohttp/nanohttp-client.c +++ b/nanohttp/nanohttp-client.c @@ -1,5 +1,5 @@ /****************************************************************** -* $Id: nanohttp-client.c,v 1.15 2004/08/30 13:28:58 snowdrop Exp $ +* $Id: nanohttp-client.c,v 1.16 2004/08/30 15:26:53 snowdrop Exp $ * * CSOAP Project: A http client/server library in C * Copyright (C) 2003 Ferhat Ayaz @@ -53,7 +53,19 @@ static struct tm *localtime_r(const time_t *const timep, struct tm *p_tm) return tmp; } -#endif +#endif
+
+/*--------------------------------------------------
+FUNCTION: httpc_init
+DESC: Initialize http client connection
+NOTE: This will be called from soap_client_init_args()
+----------------------------------------------------*/
+int httpc_init(int argc, char *argv[])
+{
+ hsocket_module_init();
+ return 0;
+}
+ /*-------------------------------------------------- FUNCTION: httpc_new DESC: Creates a new http client connection object @@ -577,12 +589,8 @@ int httpc_talk_to_server(hreq_method method, httpc_conn_t *conn, char buffer[4096]; int status; -#ifndef WIN32 - #if HSOCKET_BLOCKMODE!=0 - fcntl(conn->sock, F_SETFL, O_NONBLOCK); - #endif -#else - unsigned long iMode = HSOCKET_BLOCKMODE; +#ifdef WIN32 + unsigned long iMode = HSOCKET_NONBLOCKMODE; #endif @@ -613,10 +621,12 @@ int httpc_talk_to_server(hreq_method method, httpc_conn_t *conn, } #ifndef WIN32 -#if HSOCKET_BLOCKMODE!=0 + /* Try always non block mode
+ #if HSOCKET_BLOCKMODE!=0*/ fcntl(conn->sock, F_SETFL, O_NONBLOCK); -#endif -#else + /*#endif*/ +#else
+ iMode = HSOCKET_NONBLOCKMODE; if(ioctlsocket(conn->sock, FIONBIO, (u_long FAR*) &iMode) == INVALID_SOCKET) { log_error1("ioctlsocket error"); diff --git a/nanohttp/nanohttp-client.h b/nanohttp/nanohttp-client.h index fcb84ea..9c5cd64 100644 --- a/nanohttp/nanohttp-client.h +++ b/nanohttp/nanohttp-client.h @@ -1,5 +1,5 @@ /****************************************************************** - * $Id: nanohttp-client.h,v 1.5 2004/01/13 12:31:57 snowdrop Exp $ + * $Id: nanohttp-client.h,v 1.6 2004/08/30 15:26:53 snowdrop Exp $ * * CSOAP Project: A http client/server library in C * Copyright (C) 2003 Ferhat Ayaz @@ -50,7 +50,8 @@ typedef void (*httpc_response_callback)(int, httpc_conn_t*, void*,int,char*); */ typedef void (*httpc_response_start_callback)(httpc_conn_t*, void*, hpair_t*, const char*, int, const char*); - +
+int httpc_init(int argc, char *argv[]);
httpc_conn_t* httpc_new(); void httpc_free(httpc_conn_t* conn); diff --git a/nanohttp/nanohttp-server.c b/nanohttp/nanohttp-server.c index 0e241a7..642699b 100644 --- a/nanohttp/nanohttp-server.c +++ b/nanohttp/nanohttp-server.c @@ -1,5 +1,5 @@ /****************************************************************** -* $Id: nanohttp-server.c,v 1.10 2004/08/30 13:25:23 snowdrop Exp $ +* $Id: nanohttp-server.c,v 1.11 2004/08/30 15:26:53 snowdrop Exp $ * * CSOAP Project: A http client/server library in C * Copyright (C) 2003 Ferhat Ayaz @@ -68,11 +68,17 @@ static int _httpd_run = 1; static int _httpd_terminate_signal = SIGTERM; /* ----------------------------------------------------- -FUNCTION: httpd_init +FUNCTION: httpd_init
+NOTE: This will be called from soap_server_init_args() ----------------------------------------------------- */ int httpd_init(int argc, char *argv[]) { int i, status; +
+ status = hsocket_module_init();
+ if (status != 0)
+ return status;
+
/* write argument information */ log_verbose1("Arguments:"); @@ -356,11 +362,8 @@ int httpd_run() struct timeval timeout; -#ifndef WIN32 -#if HSOCKET_BLOCKMODE!=0 -#endif -#else - unsigned long iMode=HSOCKET_BLOCKMODE; +#ifdef WIN32 + unsigned long iMode=HSOCKET_NONBLOCKMODE; #endif pthread_attr_init(&attr); @@ -386,10 +389,12 @@ pthread_attr_init(&attr); #ifndef WIN32 -#if HSOCKET_BLOCKMODE!=0 +/* Try always non block mode
+#if HSOCKET_BLOCKMODE!=0*/ fcntl(_httpd_socket, F_SETFL, O_NONBLOCK); -#endif +/*#endif*/ #else
+ iMode = HSOCKET_NONBLOCKMODE;
if(ioctlsocket(_httpd_socket, FIONBIO, (u_long FAR*) &iMode) == INVALID_SOCKET) { log_error1("ioctlsocket error"); diff --git a/nanohttp/nanohttp-socket.c b/nanohttp/nanohttp-socket.c index 8ff722a..7aeacbc 100644 --- a/nanohttp/nanohttp-socket.c +++ b/nanohttp/nanohttp-socket.c @@ -1,5 +1,5 @@ /****************************************************************** -* $Id: nanohttp-socket.c,v 1.10 2004/08/30 07:55:42 snowdrop Exp $ +* $Id: nanohttp-socket.c,v 1.11 2004/08/30 15:26:53 snowdrop Exp $ * * CSOAP Project: A http client/server library in C * Copyright (C) 2003 Ferhat Ayaz @@ -61,19 +61,31 @@ typedef int socklen_t; /*-------------------------------------------------- FUNCTION: hsocket_module_init +NOTE: This will be called from httpd_init()
+ for server and from httpc_init() for client
----------------------------------------------------*/ int hsocket_module_init() { - /* nothing to init for unix sockets */ +#ifdef WIN32
+ // WSACleanup();
+ struct WSAData info;
+ WSAStartup(MAKEWORD(2,2), &info);
+#else
+ /* nothing to init for unix sockets */
+#endif
return 0; } /*-------------------------------------------------- -FUNCTION: hsocket_module_destroy +FUNCTION: hsocket_module_destroy
----------------------------------------------------*/ void hsocket_module_destroy() { - /* nothing to destroy for unix sockets */ +#ifdef WIN32
+ WSACleanup();
+#else
+ /* nothing to destroy for unix sockets */
+#endif
} @@ -82,13 +94,6 @@ FUNCTION: hsocket_init ----------------------------------------------------*/ int hsocket_init(hsocket_t *sock) { -#ifdef WIN32 - // WSACleanup(); - struct WSAData info; - WSAStartup(MAKEWORD(2,2), &info); -#else - /* nothing to init for unix sockets */ -#endif /* just set the descriptor to -1 */ *sock = -1; return 0; @@ -109,11 +114,7 @@ FUNCTION: hsocket_open ----------------------------------------------------*/ int hsocket_open(hsocket_t *dsock, const char* hostname, int port) { -#ifdef WIN32 - SOCKET sock; -#else - int sock; -#endif + hsocket_t sock; char *ip; struct sockaddr_in address; struct hostent* host; @@ -145,11 +146,7 @@ FUNCTION: hsocket_close ----------------------------------------------------*/ int hsocket_bind(hsocket_t *dsock, int port) { -#ifdef WIN32 - SOCKET sock; -#else - int sock; -#endif + hsocket_t sock; struct sockaddr_in addr; /* create socket */ @@ -198,7 +195,7 @@ FUNCTION: hsocket_listen int hsocket_accept(hsocket_t sock, hsocket_t *dest) { socklen_t asize; - SOCKET sockfd; + hsocket_t sockfd; struct sockaddr_in addr; asize = sizeof(struct sockaddr_in); @@ -206,7 +203,8 @@ int hsocket_accept(hsocket_t sock, hsocket_t *dest) while(1) { sockfd = accept(sock, (struct sockaddr *)&addr, &asize); - if (sockfd == -1) { + if (sockfd == INVALID_SOCKET)
+ { if(WSAGetLastError()!=WSAEWOULDBLOCK) { return HSOCKET_CAN_NOT_ACCEPT; @@ -238,9 +236,6 @@ FUNCTION: hsocket_close void hsocket_close(hsocket_t sock) { close(sock); -#ifdef WIN32 - WSACleanup(); -#endif } diff --git a/nanohttp/nanohttp-socket.h b/nanohttp/nanohttp-socket.h index f86b149..085ae0c 100644 --- a/nanohttp/nanohttp-socket.h +++ b/nanohttp/nanohttp-socket.h @@ -1,5 +1,5 @@ /****************************************************************** - * $Id: nanohttp-socket.h,v 1.6 2004/08/26 17:07:47 rans Exp $ + * $Id: nanohttp-socket.h,v 1.7 2004/08/30 15:26:53 snowdrop Exp $ * * CSOAP Project: A http client/server library in C * Copyright (C) 2003 Ferhat Ayaz @@ -24,7 +24,6 @@ #ifndef NANO_HTTP_SOCKET_H #define NANO_HTTP_SOCKET_H -#define HSOCKET_BLOCKMODE 0 #define HSOCKET_OK 0 #define HSOCKET_CAN_NOT_CREATE 1001 #define HSOCKET_CAN_NOT_GET_HOSTNAME 1002 @@ -36,6 +35,9 @@ #define HSOCKET_CAN_NOT_ACCEPT 1008 #define HSOCKET_MAX_BUFSIZE 1024 +
+#define HSOCKET_BLOCKMODE 0
+#define HSOCKET_NONBLOCKMODE 1
#ifdef WIN32 #include <winsock2.h> |