summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar snowdrop2004-08-30 15:26:48 +0000
committerGravatar snowdrop2004-08-30 15:26:48 +0000
commit30911b1730a1a69241beaca7d1ed71212d4f7b3f (patch)
tree1538c363a546cc7584f88b3886433d43aca50c77
parent056647348ff38f83b5e13bed1c4f4bb76cce50f9 (diff)
downloadcsoap-30911b1730a1a69241beaca7d1ed71212d4f7b3f.tar.gz
csoap-30911b1730a1a69241beaca7d1ed71212d4f7b3f.tar.bz2
migration win32 socket code
-rw-r--r--examples/csoap/simpleclient.c5
-rw-r--r--examples/csoap/simpleserver.c4
-rw-r--r--libcsoap/soap-client.c8
-rw-r--r--libcsoap/soap-client.h8
-rw-r--r--nanohttp/nanohttp-client.c32
-rw-r--r--nanohttp/nanohttp-client.h5
-rw-r--r--nanohttp/nanohttp-server.c23
-rw-r--r--nanohttp/nanohttp-socket.c47
-rw-r--r--nanohttp/nanohttp-socket.h6
9 files changed, 82 insertions, 56 deletions
diff --git a/examples/csoap/simpleclient.c b/examples/csoap/simpleclient.c
index f4754e4..4f2bcfe 100644
--- a/examples/csoap/simpleclient.c
+++ b/examples/csoap/simpleclient.c
@@ -1,5 +1,5 @@
/******************************************************************
- * $Id: simpleclient.c,v 1.3 2004/08/30 13:28:58 snowdrop Exp $
+ * $Id: simpleclient.c,v 1.4 2004/08/30 15:26:48 snowdrop Exp $
*
* CSOAP Project: CSOAP examples project
* Copyright (C) 2003 Ferhat Ayaz
@@ -37,6 +37,9 @@ int main(int argc, char *argv[])
SoapEnv *env, *res;
log_set_level(HLOG_VERBOSE);
+ if (!soap_client_init_args(argc, argv)) {
+ return 1;
+ }
env = soap_env_new_with_method(urn, method);
soap_env_add_item(env, "xsd:string", "name", "Jonny B. Good");
diff --git a/examples/csoap/simpleserver.c b/examples/csoap/simpleserver.c
index bdbe62b..dab8382 100644
--- a/examples/csoap/simpleserver.c
+++ b/examples/csoap/simpleserver.c
@@ -1,5 +1,5 @@
/******************************************************************
- * $Id: simpleserver.c,v 1.4 2004/08/30 13:28:58 snowdrop Exp $
+ * $Id: simpleserver.c,v 1.5 2004/08/30 15:26:49 snowdrop Exp $
*
* CSOAP Project: CSOAP examples project
* Copyright (C) 2003 Ferhat Ayaz
@@ -74,7 +74,7 @@ int main(int argc, char *argv[])
log_set_level(HLOG_VERBOSE);
if (!soap_server_init_args(argc, argv)) {
- return 0;
+ return 1;
}
router = soap_router_new();
diff --git a/libcsoap/soap-client.c b/libcsoap/soap-client.c
index 46e9192..a0038fb 100644
--- a/libcsoap/soap-client.c
+++ b/libcsoap/soap-client.c
@@ -1,5 +1,5 @@
/******************************************************************
-* $Id: soap-client.c,v 1.4 2004/08/26 17:06:18 rans Exp $
+* $Id: soap-client.c,v 1.5 2004/08/30 15:26:53 snowdrop Exp $
*
* CSOAP Project: A SOAP client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -28,7 +28,11 @@
/*--------------------------------- */
static SoapEnv *_soap_client_build_result(hresponse_t *res);
/*--------------------------------- */
-
+
+int soap_client_init_args(int argc, char *argv[])
+{
+ return !httpc_init(argc, argv);
+}
SoapEnv*
soap_client_invoke(SoapEnv *call, const char *url, const char *soap_action)
diff --git a/libcsoap/soap-client.h b/libcsoap/soap-client.h
index f3529d4..5c7cb64 100644
--- a/libcsoap/soap-client.h
+++ b/libcsoap/soap-client.h
@@ -1,5 +1,5 @@
/******************************************************************
- * $Id: soap-client.h,v 1.2 2004/02/10 09:51:10 snowdrop Exp $
+ * $Id: soap-client.h,v 1.3 2004/08/30 15:26:53 snowdrop Exp $
*
* CSOAP Project: A SOAP client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -26,6 +26,12 @@
#include <libcsoap/soap-env.h>
+
+/**
+ Initializes the client side soap engine
+*/
+int soap_client_init_args(int argc, char *argv[]);
+
/**
Establish connection to the soap server and send
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>