backported fixed for offloading, static maps and non-blocking connect

This commit is contained in:
Roberto De Ioris
2012-11-13 04:41:14 +01:00
parent 04736d371e
commit 6cf3bbea69
5 changed files with 26 additions and 25 deletions
+18 -18
View File
@@ -107,7 +107,7 @@ error:
return -1;
}
static void uwsgi_offload_close(struct uwsgi_offload_request *uor) {
static void uwsgi_offload_close(struct uwsgi_thread *ut, struct uwsgi_offload_request *uor) {
// close the socket and the file descriptor
close(uor->s);
close(uor->fd);
@@ -115,12 +115,12 @@ static void uwsgi_offload_close(struct uwsgi_offload_request *uor) {
struct uwsgi_offload_request *prev = uor->prev;
struct uwsgi_offload_request *next = uor->next;
if (uor == uwsgi.offload_requests_head) {
uwsgi.offload_requests_head = next;
if (uor == ut->offload_requests_head) {
ut->offload_requests_head = next;
}
if (uor == uwsgi.offload_requests_tail) {
uwsgi.offload_requests_tail = prev;
if (uor == ut->offload_requests_tail) {
ut->offload_requests_tail = prev;
}
if (prev) {
@@ -142,22 +142,22 @@ static void uwsgi_offload_close(struct uwsgi_offload_request *uor) {
free(uor);
}
static void uwsgi_offload_append(struct uwsgi_offload_request *uor) {
static void uwsgi_offload_append(struct uwsgi_thread *ut, struct uwsgi_offload_request *uor) {
if (!uwsgi.offload_requests_head) {
uwsgi.offload_requests_head = uor;
if (!ut->offload_requests_head) {
ut->offload_requests_head = uor;
}
if (uwsgi.offload_requests_tail) {
uwsgi.offload_requests_tail->next = uor;
uor->prev = uwsgi.offload_requests_tail;
if (ut->offload_requests_tail) {
ut->offload_requests_tail->next = uor;
uor->prev = ut->offload_requests_tail;
}
uwsgi.offload_requests_tail = uor;
ut->offload_requests_tail = uor;
}
static struct uwsgi_offload_request *uwsgi_offload_get_by_fd(int s) {
struct uwsgi_offload_request *uor = uwsgi.offload_requests_head;
static struct uwsgi_offload_request *uwsgi_offload_get_by_fd(struct uwsgi_thread *ut, int s) {
struct uwsgi_offload_request *uor = ut->offload_requests_head;
while (uor) {
if (uor->s == s || uor->fd == s) {
return uor;
@@ -187,20 +187,20 @@ static void uwsgi_offload_loop(struct uwsgi_thread *ut) {
}
// start monitoring socket for write
if (uor->func(ut, uor, -1)) {
uwsgi_offload_close(uor);
uwsgi_offload_close(ut, uor);
continue;
}
uwsgi_offload_append(uor);
uwsgi_offload_append(ut, uor);
continue;
}
// get the task from the interesting fd
struct uwsgi_offload_request *uor = uwsgi_offload_get_by_fd(interesting_fd);
struct uwsgi_offload_request *uor = uwsgi_offload_get_by_fd(ut, interesting_fd);
if (!uor)
continue;
// run the hook
if (uor->func(ut, uor, interesting_fd)) {
uwsgi_offload_close(uor);
uwsgi_offload_close(ut, uor);
}
}
}
+3 -1
View File
@@ -1082,7 +1082,7 @@ nextcs:
udd = uwsgi.static_maps;
while (udd) {
#ifdef UWSGI_DEBUG
uwsgi_log("checking for %.*s <-> %.*s\n", wsgi_req->path_info_len, wsgi_req->path_info, udd->keylen, udd->key);
uwsgi_log("checking for %.*s <-> %.*s %.*s\n", (int)wsgi_req->path_info_len, wsgi_req->path_info, (int)udd->keylen, udd->key, (int) udd->vallen, udd->value);
#endif
if (udd->status == 0) {
#ifdef UWSGI_THREADING
@@ -1092,6 +1092,7 @@ nextcs:
char *real_docroot = uwsgi_malloc(PATH_MAX + 1);
if (!realpath(udd->value, real_docroot)) {
free(real_docroot);
real_docroot = NULL;
udd->value = NULL;
}
#ifdef UWSGI_THREADING
@@ -1128,6 +1129,7 @@ nextsm:
char *real_docroot = uwsgi_malloc(PATH_MAX + 1);
if (!realpath(udd->value, real_docroot)) {
free(real_docroot);
real_docroot = NULL;
udd->value = NULL;
}
#ifdef UWSGI_THREADING
+1 -1
View File
@@ -718,7 +718,7 @@ int timed_connect(struct pollfd *fdpoll, const struct sockaddr *addr, int addr_s
#if defined(__linux__) && defined(SOCK_NONBLOCK) && !defined(OBSOLETE_LINUX_KERNEL)
// hmm, nothing to do, as we are already non-blocking
uwsgi_socket_b(fdpoll->fd);
#else
/* re-set blocking socket */
arg &= (~O_NONBLOCK);
+1 -1
View File
@@ -4806,7 +4806,7 @@ static void *uwsgi_thread_run(void *arg) {
struct uwsgi_thread *uwsgi_thread_new(void (*func) (struct uwsgi_thread *)) {
struct uwsgi_thread *ut = uwsgi_malloc(sizeof(struct uwsgi_thread));
struct uwsgi_thread *ut = uwsgi_calloc(sizeof(struct uwsgi_thread));
#if defined(SOCK_SEQPACKET) && defined(__linux__)
if (socketpair(AF_UNIX, SOCK_SEQPACKET, 0, ut->pipe)) {
+3 -4
View File
@@ -1529,10 +1529,6 @@ struct uwsgi_server {
int check_static_docroot;
// linked list for offloaded requests
struct uwsgi_offload_request *offload_requests_head;
struct uwsgi_offload_request *offload_requests_tail;
char *daemonize;
char *daemonize2;
int do_not_change_umask;
@@ -3409,6 +3405,9 @@ struct uwsgi_thread {
uint64_t custom1;
uint64_t custom2;
uint64_t custom3;
// linked list for offloaded requests
struct uwsgi_offload_request *offload_requests_head;
struct uwsgi_offload_request *offload_requests_tail;
void (*func)(struct uwsgi_thread *);
};
struct uwsgi_thread *uwsgi_thread_new(void (*)(struct uwsgi_thread *));