From: Urban Wallasch Date: Sat, 26 Oct 2019 08:41:02 +0000 (+0200) Subject: * Improved printf formats and debug code. X-Git-Tag: v0.1.0~5 X-Git-Url: https://git.packet-gain.de/?a=commitdiff_plain;h=6f0b0ca5821301242f0fa82c49fc5cae18b80e43;p=ets2_tele.git * Improved printf formats and debug code. --- diff --git a/telehttpd.c b/telehttpd.c index 95363c4..a219c84 100644 --- a/telehttpd.c +++ b/telehttpd.c @@ -25,6 +25,7 @@ struct thread_data_t { int sock; + int id; }; struct { @@ -170,11 +171,11 @@ static int respond( int sock, const char *req ) { "Access-Control-Allow-Origin: %s\r\n" "Content-type: text/json\r\n" "Connection: keep-alive\r\n" - "Content-Length: %lu\r\n" + "Content-Length: %zu\r\n" "\r\n", host, origin, - (unsigned long)jsz + jsz ); if ( 0 < n && (size_t)n < sizeof hdr && n == sockwrite( sock, hdr, n ) ) ret = sockwrite( sock, jbuf, jsz ); @@ -195,10 +196,10 @@ static int respond( int sock, const char *req ) { "Host: %s\r\n" "Content-type: text/html\r\n" "Connection: keep-alive\r\n" - "Content-Length: %ld\r\n" + "Content-Length: %jd\r\n" "\r\n", host, - (long)st.st_size + (intmax_t)st.st_size ); if ( 0 < n && (size_t)n < sizeof hdr && n == sockwrite( sock, hdr, n ) ) { ret = sendfile_tm( sock, fi, st.st_size, 1000 ); @@ -270,7 +271,7 @@ static void *handle_conn( void *p ) { struct thread_data_t *td = p; char req[2048]; - DPRINT("-- new thread --\n"); + DPRINT( "-- thread %d started --\n", td->id ); DPRINT( "sock: %d\n", td->sock ); while ( 0 == rcv_request(td->sock, req, sizeof req, 5000) ) { DPRINT( "request:\n%s", req); @@ -278,13 +279,13 @@ static void *handle_conn( void *p ) { break; } net_close( td->sock ); + DPRINT( "-- thread %d terminating --\n", td->id ); free( td ); - DPRINT("-- thread terminated --\n"); return NULL; } static int serve_http(void) { - int as, ss; + int as, ss, id = 0; struct thread_data_t *td; pthread_t tid; pthread_attr_t attr; @@ -307,6 +308,7 @@ static int serve_http(void) { if ( NULL != (td = malloc( sizeof *td )) ) { int e; td->sock = as; + td->id = ++id; pthread_attr_init( &attr ); pthread_attr_setdetachstate( &attr, PTHREAD_CREATE_DETACHED ); if ( 0 != ( e = pthread_create( &tid, &attr, handle_conn, td ) ) ) {