summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar default2023-02-06 19:23:35 +0100
committerGravatar default2023-02-06 19:23:35 +0100
commit8b465a586d7d8e6e10e2c69e91767e0d1ff9477a (patch)
treef87134c005619833723e22b66fdb9523858ca791
parentMore thread work. (diff)
downloadsnac2-8b465a586d7d8e6e10e2c69e91767e0d1ff9477a.tar.gz
snac2-8b465a586d7d8e6e10e2c69e91767e0d1ff9477a.tar.xz
snac2-8b465a586d7d8e6e10e2c69e91767e0d1ff9477a.zip
Incoming connections are processed by the pool of threads.
-rw-r--r--httpd.c28
1 files changed, 13 insertions, 15 deletions
diff --git a/httpd.c b/httpd.c
index addbf7c..5f6be27 100644
--- a/httpd.c
+++ b/httpd.c
@@ -312,14 +312,6 @@ static void *background_thread(void *arg)
312} 312}
313 313
314 314
315static void *connection_thread(void *arg)
316/* connection thread */
317{
318 httpd_connection((FILE *)arg);
319 return NULL;
320}
321
322
323/** job control **/ 315/** job control **/
324 316
325/* mutex to access the lists of jobs */ 317/* mutex to access the lists of jobs */
@@ -376,25 +368,32 @@ void job_wait(xs_val **job)
376static void *job_thread(void *arg) 368static void *job_thread(void *arg)
377/* job thread */ 369/* job thread */
378{ 370{
379// httpd_connection((FILE *)arg); 371 int pid = pthread_self();
380 srv_debug(0, xs_fmt("job thread started")); 372
373 srv_debug(0, xs_fmt("job thread %x started", pid));
381 374
382 for (;;) { 375 for (;;) {
383 xs *job = NULL; 376 xs *job = NULL;
384 377
385 job_wait(&job); 378 job_wait(&job);
386 379
387 srv_debug(0, xs_fmt("job thread wake up")); 380 srv_debug(0, xs_fmt("job thread %x wake up", pid));
388 381
389 if (job == NULL) 382 if (job == NULL)
390 break; 383 break;
391 384
392 if (xs_type(job) == XSTYPE_DATA) { 385 if (xs_type(job) == XSTYPE_DATA) {
393 /* it's a socket */ 386 /* it's a socket */
387 FILE *f = NULL;
388
389 xs_data_get(job, &f);
390
391 if (f != NULL)
392 httpd_connection(f);
394 } 393 }
395 } 394 }
396 395
397 srv_debug(0, xs_fmt("job thread stopped")); 396 srv_debug(0, xs_fmt("job thread %x stopped", pid));
398 397
399 return NULL; 398 return NULL;
400} 399}
@@ -455,10 +454,9 @@ void httpd(void)
455 for (;;) { 454 for (;;) {
456 FILE *f = xs_socket_accept(rs); 455 FILE *f = xs_socket_accept(rs);
457 456
458 pthread_t cth; 457 xs *job = xs_data_new(&f, sizeof(FILE *));
459 458
460 pthread_create(&cth, NULL, connection_thread, f); 459 job_post(job);
461 pthread_detach(cth);
462 } 460 }
463 } 461 }
464 462