struct thread_data_t {
int sock;
+ int id;
};
struct {
"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 );
"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 );
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);
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;
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 ) ) ) {