mirror of
https://github.com/asterisk/asterisk.git
synced 2025-10-13 00:04:53 +00:00
in the helper thread, separate the FILE * creation from the actual
function doing work on the socket. This is another generalization to provide a generic mechanism to open TCP/TLS socket with a thread managing the accpet and children threads managing the individual sessions. git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@48067 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
30
main/http.c
30
main/http.c
@@ -92,6 +92,7 @@ struct server_instance {
|
|||||||
SSL *ssl; /* ssl state */
|
SSL *ssl; /* ssl state */
|
||||||
#endif
|
#endif
|
||||||
struct sockaddr_in requestor;
|
struct sockaddr_in requestor;
|
||||||
|
struct server_args *parent;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@@ -483,14 +484,14 @@ static int ssl_close(void *cookie)
|
|||||||
}
|
}
|
||||||
#endif /* DO_SSL */
|
#endif /* DO_SSL */
|
||||||
|
|
||||||
static void *httpd_helper_thread(void *data)
|
/*!
|
||||||
|
* creates a FILE * from the fd passed by the accept thread.
|
||||||
|
* This operation is potentially expensive (certificate verification),
|
||||||
|
* so we do it in the child thread context.
|
||||||
|
*/
|
||||||
|
static void *make_file_from_fd(void *data)
|
||||||
{
|
{
|
||||||
char buf[4096];
|
|
||||||
char cookie[4096];
|
|
||||||
struct server_instance *ser = data;
|
struct server_instance *ser = data;
|
||||||
struct ast_variable *var, *prev=NULL, *vars=NULL;
|
|
||||||
char *uri, *c, *title=NULL;
|
|
||||||
int status = 200, contentlength = 0;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* open a FILE * as appropriate.
|
* open a FILE * as appropriate.
|
||||||
@@ -523,8 +524,20 @@ static void *httpd_helper_thread(void *data)
|
|||||||
if (!ser->f) {
|
if (!ser->f) {
|
||||||
close(ser->fd);
|
close(ser->fd);
|
||||||
ast_log(LOG_WARNING, "FILE * open failed!\n");
|
ast_log(LOG_WARNING, "FILE * open failed!\n");
|
||||||
goto done;
|
free(ser);
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
return ser->parent->worker_fn(ser);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void *httpd_helper_thread(void *data)
|
||||||
|
{
|
||||||
|
char buf[4096];
|
||||||
|
char cookie[4096];
|
||||||
|
struct server_instance *ser = data;
|
||||||
|
struct ast_variable *var, *prev=NULL, *vars=NULL;
|
||||||
|
char *uri, *c, *title=NULL;
|
||||||
|
int status = 200, contentlength = 0;
|
||||||
|
|
||||||
if (!fgets(buf, sizeof(buf), ser->f))
|
if (!fgets(buf, sizeof(buf), ser->f))
|
||||||
goto done;
|
goto done;
|
||||||
@@ -674,12 +687,13 @@ static void *http_root(void *data)
|
|||||||
fcntl(fd, F_SETFL, flags & ~O_NONBLOCK);
|
fcntl(fd, F_SETFL, flags & ~O_NONBLOCK);
|
||||||
ser->fd = fd;
|
ser->fd = fd;
|
||||||
ser->is_ssl = desc->is_ssl;
|
ser->is_ssl = desc->is_ssl;
|
||||||
|
ser->parent = desc;
|
||||||
memcpy(&ser->requestor, &sin, sizeof(ser->requestor));
|
memcpy(&ser->requestor, &sin, sizeof(ser->requestor));
|
||||||
|
|
||||||
pthread_attr_init(&attr);
|
pthread_attr_init(&attr);
|
||||||
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
|
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
|
||||||
|
|
||||||
if (ast_pthread_create_background(&launched, &attr, desc->worker_fn, ser)) {
|
if (ast_pthread_create_background(&launched, &attr, make_file_from_fd, ser)) {
|
||||||
ast_log(LOG_WARNING, "Unable to launch helper thread: %s\n", strerror(errno));
|
ast_log(LOG_WARNING, "Unable to launch helper thread: %s\n", strerror(errno));
|
||||||
close(ser->fd);
|
close(ser->fd);
|
||||||
free(ser);
|
free(ser);
|
||||||
|
Reference in New Issue
Block a user