mirror of
https://codeberg.org/grunfink/snac2.git
synced 2024-11-10 03:50:38 +03:00
Incoming connections are processed by the pool of threads.
This commit is contained in:
parent
451d964c0c
commit
8b465a586d
28
httpd.c
28
httpd.c
@ -312,14 +312,6 @@ static void *background_thread(void *arg)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void *connection_thread(void *arg)
|
|
||||||
/* connection thread */
|
|
||||||
{
|
|
||||||
httpd_connection((FILE *)arg);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/** job control **/
|
/** job control **/
|
||||||
|
|
||||||
/* mutex to access the lists of jobs */
|
/* mutex to access the lists of jobs */
|
||||||
@ -376,25 +368,32 @@ void job_wait(xs_val **job)
|
|||||||
static void *job_thread(void *arg)
|
static void *job_thread(void *arg)
|
||||||
/* job thread */
|
/* job thread */
|
||||||
{
|
{
|
||||||
// httpd_connection((FILE *)arg);
|
int pid = pthread_self();
|
||||||
srv_debug(0, xs_fmt("job thread started"));
|
|
||||||
|
srv_debug(0, xs_fmt("job thread %x started", pid));
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
xs *job = NULL;
|
xs *job = NULL;
|
||||||
|
|
||||||
job_wait(&job);
|
job_wait(&job);
|
||||||
|
|
||||||
srv_debug(0, xs_fmt("job thread wake up"));
|
srv_debug(0, xs_fmt("job thread %x wake up", pid));
|
||||||
|
|
||||||
if (job == NULL)
|
if (job == NULL)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (xs_type(job) == XSTYPE_DATA) {
|
if (xs_type(job) == XSTYPE_DATA) {
|
||||||
/* it's a socket */
|
/* it's a socket */
|
||||||
|
FILE *f = NULL;
|
||||||
|
|
||||||
|
xs_data_get(job, &f);
|
||||||
|
|
||||||
|
if (f != NULL)
|
||||||
|
httpd_connection(f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
srv_debug(0, xs_fmt("job thread stopped"));
|
srv_debug(0, xs_fmt("job thread %x stopped", pid));
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -455,10 +454,9 @@ void httpd(void)
|
|||||||
for (;;) {
|
for (;;) {
|
||||||
FILE *f = xs_socket_accept(rs);
|
FILE *f = xs_socket_accept(rs);
|
||||||
|
|
||||||
pthread_t cth;
|
xs *job = xs_data_new(&f, sizeof(FILE *));
|
||||||
|
|
||||||
pthread_create(&cth, NULL, connection_thread, f);
|
job_post(job);
|
||||||
pthread_detach(cth);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user