From e35190e23d2b09c18cbe944dab14c9426614bfa7 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Fri, 31 Oct 2014 08:48:48 +0000 Subject: [PATCH] changed debugging ouput tput format --- qse/lib/http/httpd-std.c | 2 +- qse/lib/http/httpd.c | 60 +++++++++++++++++++++++++--------------- qse/lib/http/httpd.h | 24 +++++++++------- 3 files changed, 53 insertions(+), 33 deletions(-) diff --git a/qse/lib/http/httpd-std.c b/qse/lib/http/httpd-std.c index 8cfa4fb8..51f5a43c 100644 --- a/qse/lib/http/httpd-std.c +++ b/qse/lib/http/httpd-std.c @@ -936,7 +936,7 @@ static int server_open (qse_httpd_t* httpd, qse_httpd_server_t* server) { /* TODO: logging. warning only */ /* this is not a hard failure */ -qse_fprintf (QSE_STDERR, QSE_T("Failed to enable SO_REUSEPORT\n")); + HTTPD_DBGOUT1 ("Failed to enable SO_REUSERPORT on %zd\n", (qse_size_t)fd); } #endif diff --git a/qse/lib/http/httpd.c b/qse/lib/http/httpd.c index ebeb8253..9834284f 100644 --- a/qse/lib/http/httpd.c +++ b/qse/lib/http/httpd.c @@ -541,7 +541,7 @@ static void free_client ( #if defined(QSE_HTTPD_DEBUG) { qse_mchar_t tmp[128]; - qse_nwadtombs (&client->remote_addr, tmp, QSE_COUNTOF(tmp), QSE_NWADTOSTR_ALL); + qse_nwadtombs (&client->remote_addr, tmp, QSE_COUNTOF(tmp), QSE_NWADTOMBS_ALL); HTTPD_DBGOUT2 ("Closing client [%hs] - %zd\n", tmp, (qse_size_t)client->handle); } #endif @@ -579,7 +579,7 @@ static void purge_client (qse_httpd_t* httpd, qse_httpd_client_t* client) #if defined(QSE_HTTPD_DEBUG) { qse_mchar_t tmp[128]; - qse_nwadtombs (&client->remote_addr, tmp, QSE_COUNTOF(tmp), QSE_NWADTOSTR_ALL); + qse_nwadtombs (&client->remote_addr, tmp, QSE_COUNTOF(tmp), QSE_NWADTOMBS_ALL); HTTPD_DBGOUT2 ("Purged client [%hs] - %zd\n", tmp, (qse_size_t)client->handle); } #endif @@ -656,7 +656,7 @@ static int accept_client ( { #if QSE_HTTPD_DEBUG qse_mchar_t tmp[128]; - qse_nwadtombs (&server->dope.nwad, tmp, QSE_COUNTOF(tmp), QSE_NWADTOSTR_ALL); + qse_nwadtombs (&server->dope.nwad, tmp, QSE_COUNTOF(tmp), QSE_NWADTOMBS_ALL); HTTPD_DBGOUT2 ("Failed to accept from server [%hs] [%d]\n", tmp, (int)server->handle); #endif return -1; @@ -708,9 +708,9 @@ static int accept_client ( #if defined(QSE_HTTPD_DEBUG) { qse_mchar_t tmp1[128], tmp2[128], tmp3[128]; - qse_nwadtombs (&client->local_addr, tmp1, QSE_COUNTOF(tmp1), QSE_NWADTOSTR_ALL); - qse_nwadtombs (&client->orgdst_addr, tmp2, QSE_COUNTOF(tmp2), QSE_NWADTOSTR_ALL); - qse_nwadtombs (&client->remote_addr, tmp3, QSE_COUNTOF(tmp3), QSE_NWADTOSTR_ALL); + qse_nwadtombs (&client->local_addr, tmp1, QSE_COUNTOF(tmp1), QSE_NWADTOMBS_ALL); + qse_nwadtombs (&client->orgdst_addr, tmp2, QSE_COUNTOF(tmp2), QSE_NWADTOMBS_ALL); + qse_nwadtombs (&client->remote_addr, tmp3, QSE_COUNTOF(tmp3), QSE_NWADTOMBS_ALL); HTTPD_DBGOUT3 ("Accepted client %hs(%hs) from %hs\n", tmp1, tmp2, tmp3); } #endif @@ -774,6 +774,14 @@ static void deactivate_servers (qse_httpd_t* httpd) { if (server->dope.flags & QSE_HTTPD_SERVER_ACTIVE) { + #if defined(QSE_HTTPD_DEBUG) + { + qse_mchar_t tmp[128]; + qse_nwadtombs (&server->dope.nwad, tmp, QSE_COUNTOF(tmp), QSE_NWADTOMBS_ALL); + HTTPD_DBGOUT2 ("Closing server [%hs] %zd to mux\n", tmp, (qse_size_t)server->handle); + } + #endif + httpd->opt.scb.mux.delhnd (httpd, httpd->mux, server->handle); httpd->opt.scb.server.close (httpd, server); server->dope.flags &= ~QSE_HTTPD_SERVER_ACTIVE; @@ -792,29 +800,37 @@ static int activate_servers (qse_httpd_t* httpd) if (httpd->opt.scb.server.open (httpd, server) <= -1) { - qse_char_t buf[64]; - qse_nwadtostr (&server->dope.nwad, buf, QSE_COUNTOF(buf), QSE_NWADTOSTR_ALL); + #if defined(QSE_HTTPD_DEBUG) + { + qse_mchar_t tmp[128]; + qse_nwadtombs (&server->dope.nwad, tmp, QSE_COUNTOF(tmp), QSE_NWADTOMBS_ALL); + HTTPD_DBGOUT1 ("Cannot open server [%hs]\n", tmp); + } + #endif -/* - httpd->opt.rcb.log (httpd, 0, QSE_T("cannot activate %s"), buf); -*/ -#if 1 -qse_printf(QSE_T("cannot activate [%s]\n"), buf); -#endif continue; } + else + { + #if defined(QSE_HTTPD_DEBUG) + { + qse_mchar_t tmp[128]; + qse_nwadtombs (&server->dope.nwad, tmp, QSE_COUNTOF(tmp), QSE_NWADTOMBS_ALL); + HTTPD_DBGOUT2 ("Opened server [%hs] - %zd\n", tmp, (qse_size_t)server->handle); + } + #endif + } if (httpd->opt.scb.mux.addhnd ( httpd, httpd->mux, server->handle, QSE_HTTPD_MUX_READ, server) <= -1) { - qse_char_t buf[64]; - qse_nwadtostr (&server->dope.nwad, buf, QSE_COUNTOF(buf), QSE_NWADTOSTR_ALL); -/* - httpd->opt.rcb.log (httpd, 0, QSE_T("cannot activate %s - "), buf); -*/ -#if 1 -qse_printf(QSE_T("cannot add handle [%s]\n"), buf); -#endif + #if defined(QSE_HTTPD_DEBUG) + { + qse_mchar_t tmp[128]; + qse_nwadtombs (&server->dope.nwad, tmp, QSE_COUNTOF(tmp), QSE_NWADTOMBS_ALL); + HTTPD_DBGOUT2 ("Cannot add server [%hs] %zd to mux. Closing\n", tmp, (qse_size_t)server->handle); + } + #endif httpd->opt.scb.server.close (httpd, server); continue; diff --git a/qse/lib/http/httpd.h b/qse/lib/http/httpd.h index 4cafc340..e4916e54 100644 --- a/qse/lib/http/httpd.h +++ b/qse/lib/http/httpd.h @@ -24,21 +24,20 @@ /* private header file for httpd */ #include -#include - -#define QSE_HTTPD_DEFAULT_PORT 80 -#define QSE_HTTPD_DEFAULT_SECURE_PORT 443 #define QSE_HTTPD_DEBUG 1 /*#undef QSE_HTTPD_DEBUG*/ + #if defined(QSE_HTTPD_DEBUG) -# define HTTPD_DBGOUT0(fmt) qse_putmbsf("%hs:%d: " fmt, __FILE__, (int)__LINE__) -# define HTTPD_DBGOUT1(fmt,a1) qse_putmbsf("%hs:%d: " fmt, __FILE__, (int)__LINE__, (a1)) -# define HTTPD_DBGOUT2(fmt,a1,a2) qse_putmbsf("%hs:%d: " fmt, __FILE__, (int)__LINE__, (a1), (a2)) -# define HTTPD_DBGOUT3(fmt,a1,a2,a3) qse_putmbsf("%hs:%d: " fmt, __FILE__, (int)__LINE__, (a1), (a2), (a3)) -# define HTTPD_DBGOUT4(fmt,a1,a2,a3,a4) qse_putmbsf("%hs:%d: " fmt, __FILE__, (int)__LINE__, (a1), (a2), (a3), (a4)) -# define HTTPD_DBGOUT5(fmt,a1,a2,a3,a4,a5) qse_putmbsf("%hs:%d: " fmt, __FILE__, (int)__LINE__, (a1), (a2), (a3), (a4), (a5)) +# include +# include +# define HTTPD_DBGOUT0(fmt) qse_putmbsf("%06d %-20hs " fmt, (int)__LINE__, qse_mbsbasename(__FILE__)) +# define HTTPD_DBGOUT1(fmt,a1) qse_putmbsf("%06d %-20hs " fmt, (int)__LINE__, qse_mbsbasename(__FILE__), (a1)) +# define HTTPD_DBGOUT2(fmt,a1,a2) qse_putmbsf("%06d %-20hs " fmt, (int)__LINE__, qse_mbsbasename(__FILE__), (a1), (a2)) +# define HTTPD_DBGOUT3(fmt,a1,a2,a3) qse_putmbsf("%06d %-20hs " fmt, (int)__LINE__, qse_mbsbasename(__FILE__), (a1), (a2), (a3)) +# define HTTPD_DBGOUT4(fmt,a1,a2,a3,a4) qse_putmbsf("%06d %-20hs " fmt, (int)__LINE__, qse_mbsbasename(__FILE__), (a1), (a2), (a3), (a4)) +# define HTTPD_DBGOUT5(fmt,a1,a2,a3,a4,a5) qse_putmbsf("%06d %-20hs " fmt, (int)__LINE__, qse_mbsbasename(__FILE__), (a1), (a2), (a3), (a4), (a5)) #else # define HTTPD_DBGOUT0(fmt) # define HTTPD_DBGOUT1(fmt,a1) @@ -48,6 +47,11 @@ # define HTTPD_DBGOUT5(fmt,a1,a2,a3,a4,a5) #endif + +#define QSE_HTTPD_DEFAULT_PORT 80 +#define QSE_HTTPD_DEFAULT_SECURE_PORT 443 + + struct qse_httpd_t { qse_mmgr_t* mmgr;