Skip to content

Commit

Permalink
little refactoring for the fastrouter
Browse files Browse the repository at this point in the history
  • Loading branch information
roberto@precise64 committed Mar 4, 2012
1 parent 205605a commit da9ce52
Show file tree
Hide file tree
Showing 12 changed files with 845 additions and 625 deletions.
13 changes: 13 additions & 0 deletions gateway.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,16 @@ struct uwsgi_gateway_socket *uwsgi_new_gateway_socket_from_fd(int fd, char *owne
}


void uwsgi_gateway_go_cheap(char *gw_id, int queue, int *i_am_cheap) {

uwsgi_log("[%s pid %d] no more nodes available. Going cheap...\n", gw_id, (int) uwsgi.mypid);
struct uwsgi_gateway_socket *ugs = uwsgi.gateway_sockets;
while (ugs) {
if (!strcmp(ugs->owner, gw_id) && !ugs->subscription) {
event_queue_del_fd(queue, ugs->fd, event_queue_read());
}
ugs = ugs->next;
}
*i_am_cheap = 1;
}

1 change: 1 addition & 0 deletions hello_world.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
#uwsgi.cache_set('/', "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\nHello World from cache")
def application(env, start_response):
start_response('200 OK', [('Content-Type', 'text/html')])
yield "foobar"
yield str(env['wsgi.input'].fileno())
yield "<h1>Hello World</h1>"
17 changes: 2 additions & 15 deletions lib/corerouter.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,19 +91,6 @@ static void *uwsgi_corerouter_setup_event_queue(char *gw_id, int id, int nevents
return event_queue_alloc(nevents);
}

static void __attribute__ ((unused)) uwsgi_corerouter_go_cheap(char *gw_id, int queue, int *i_am_cheap) {

uwsgi_log("[%s pid %d] no more nodes available. Going cheap...\n", gw_id, (int) uwsgi.mypid);
struct uwsgi_gateway_socket *ugs = uwsgi.gateway_sockets;
while (ugs) {
if (!strcmp(ugs->owner, gw_id) && !ugs->subscription) {
event_queue_del_fd(queue, ugs->fd, event_queue_read());
}
ugs = ugs->next;
}
*i_am_cheap = 1;
}

static void __attribute__ ((unused)) uwsgi_corerouter_manage_subscription(char *gw_id, int id, struct uwsgi_gateway_socket *ugs, int queue, struct uwsgi_subscribe_slot **subscriptions, int regexp, void (*parse_hook) (char *, uint16_t, char *, uint16_t, void *), int cheap, int *i_am_cheap) {

int i;
Expand Down Expand Up @@ -145,7 +132,7 @@ static void __attribute__ ((unused)) uwsgi_corerouter_manage_subscription(char *
uwsgi_remove_subscribe_node(subscriptions, node);
}
if (*subscriptions == NULL && cheap && !*i_am_cheap) {
uwsgi_corerouter_go_cheap(gw_id, queue, i_am_cheap);
uwsgi_gateway_go_cheap(gw_id, queue, i_am_cheap);
}
}
}
Expand Down Expand Up @@ -205,7 +192,7 @@ static void __attribute__ ((unused)) uwsgi_corerouter_manage_internal_subscripti
uwsgi_remove_subscribe_node(subscriptions, node);
}
if (*subscriptions == NULL && cheap && !*i_am_cheap) {
uwsgi_corerouter_go_cheap(gw_id, queue, i_am_cheap);
uwsgi_gateway_go_cheap(gw_id, queue, i_am_cheap);
}
}
}
Expand Down
Loading

0 comments on commit da9ce52

Please sign in to comment.