mutithread_web_server_2

mutithread_web_server_2 -...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
#include "soapH.h" #include "webserver.nsmap" #include "httpget.h" #include <pthread.h> # #define BACKLOG (100) #define SERVER_TIMEOUT (24*60*60) /* die after 24 hrs waiting */ #define IO_TIMEOUT (60) /* deny serving slow clients */ #define COOKIE_DOMAIN "localhost:8080" /* must be your current domain for cookies to work */ t #define AUTH_USERID "admin" #define AUTH_PASSWD "guest" # static time_t start = 0; static int secure = 0; /* =0: no SSL, =1: SSL */ / void *process_request(void*); /* multi-threaded request handler */ / int http_get_handler(struct soap*); /* HTTP get handler */ int check_authentication(struct soap*); /* HTTP authentication check */ int copy_file(struct soap*, const char*, const char*); /* copy file as HTTP response */ int calc(struct soap*); int info(struct soap*); int html_hbar(struct soap*, const char*, size_t, unsigned long); i void CRYPTO_thread_setup(); void CRYPTO_thread_cleanup(); v /******************************************************************************\ * * Main * \******************************************************************************/ \ int main(int argc, char **argv) { struct soap soap, *tsoap; pthread_t tid; int port = 80; int m, s, i; if (argc >= 2) port = atoi(argv[1]); start = time(NULL); fprintf(stderr, "Starting Web server on port %d\n", port); soap_init2(&soap, SOAP_IO_KEEPALIVE, SOAP_IO_KEEPALIVE); /* HTTP cookies (to enable: compile all sources with -DWITH_COOKIES) */ soap.cookie_domain = COOKIE_DOMAIN; /* must be the current host name */ soap.cookie_path = "/"; /* the path which is used to filter/set cookies with this destination */ /* SSL init (to enable: compile all sources with -DWITH_OPENSSL) */ #ifdef WITH_OPENSSL CRYPTO_thread_setup(); /* if the port is an odd number, the Web server uses HTTPS only */ if (port % 2) secure = 1; if (secure) { soap.keyfile = "server.pem";/* see SSL docs on how to obtain this file */ soap.password = "password"; /* your password */
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
soap.cafile = "cacert.pem"; /* see SSL docs on how to obtain this file */ soap.dhfile = "dh512.pem"; /* see SSL docs on how to obtain this file */ soap.randfile = NULL; /* if randfile!=NULL: use a file with random data to seed randomness */ } #endif /* Register HTTP GET plugin */ soap_register_plugin_arg(&soap, http_get, (void*)http_get_handler); /* Unix SIGPIPE, this is OS dependent */ soap.accept_flags = SO_NOSIGPIPE; /* some systems like this */ /* soap.socket_flags = MSG_NOSIGNAL; */ /* others need this */ m = soap_bind(&soap, NULL, port, BACKLOG); if (m < 0) { soap_print_fault(&soap, stderr); exit(1); } fprintf(stderr, "Port bind successful: master socket = %d\n", m); soap.accept_timeout = SERVER_TIMEOUT; soap.send_timeout = IO_TIMEOUT; soap.recv_timeout = IO_TIMEOUT; for (i = 1; ; i++) { s = soap_accept(&soap); if (s < 0) { if (soap.errnum) { soap_print_fault(&soap, stderr); exit(1); } fprintf(stderr, "gSOAP Web server timed out\n"); break; } fprintf(stderr, "Thread %d accepts socket %d connection from IP %d.%d.%d.%d\n",
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 9

mutithread_web_server_2 -...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online