Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

pcre support in subscription system

  • Loading branch information...
commit 5594503a56b19bc96f34a6c548aff0438ae010a9 1 parent d57e5d4
roberto@debian32 authored
5 master_utils.c
View
@@ -101,8 +101,9 @@ int uwsgi_respawn_worker(int wid) {
uwsgi.workers[uwsgi.mywid].pid = uwsgi.mypid;
uwsgi.workers[uwsgi.mywid].id = uwsgi.mywid;
uwsgi.workers[uwsgi.mywid].harakiri = 0;
- uwsgi.workers[uwsgi.mywid].requests = 0;
- uwsgi.workers[uwsgi.mywid].failed_requests = 0;
+ // do not reset worker counters on reload !!!
+ //uwsgi.workers[uwsgi.mywid].requests = 0;
+ //uwsgi.workers[uwsgi.mywid].failed_requests = 0;
uwsgi.workers[uwsgi.mywid].respawn_count++;
uwsgi.workers[uwsgi.mywid].last_spawn = uwsgi.current_time;
uwsgi.workers[uwsgi.mywid].manage_next_request = 1;
5 plugins/fastrouter/fastrouter.c
View
@@ -435,8 +435,7 @@ void fastrouter_loop() {
if (len > 0) {
memset(&usr, 0, sizeof(struct uwsgi_subscribe_req));
uwsgi_hooked_parse(bbuf+4, len-4, fastrouter_manage_subscription, &usr);
- uwsgi_add_subscribe_node(&ufr.subscriptions, &usr, 0);
- if (ufr.i_am_cheap) {
+ if (uwsgi_add_subscribe_node(&ufr.subscriptions, &usr, 0) && ufr.i_am_cheap) {
struct uwsgi_fastrouter_socket *ufr_sock = ufr.sockets;
while(ufr_sock) {
event_queue_add_fd_read(ufr.queue, ufr_sock->fd);
@@ -704,7 +703,7 @@ void fastrouter_loop() {
// fallback to destroy !!!
default:
- uwsgi_log("default action\n");
+ uwsgi_log("unknown event: closing session\n");
close_session(fr_table, fr_session);
break;
36 regexp.c
View
@@ -1,7 +1,7 @@
#ifdef UWSGI_PCRE
#include "uwsgi.h"
-void uwsgi_regexp_build(char *re, pcre **pattern, pcre_extra **pattern_extra) {
+int uwsgi_regexp_build(char *re, pcre **pattern, pcre_extra **pattern_extra) {
const char *errstr;
int erroff;
@@ -9,15 +9,17 @@ void uwsgi_regexp_build(char *re, pcre **pattern, pcre_extra **pattern_extra) {
*pattern = pcre_compile( (const char *)re, 0, &errstr, &erroff, NULL);
if (!*pattern) {
uwsgi_log("pcre error: %s at offset %d\n", errstr, erroff);
- exit(1);
+ return -1;
}
*pattern_extra = (pcre_extra *) pcre_study((const pcre*)*pattern, 0, &errstr);
if (!*pattern_extra) {
+ pcre_free(*pattern);
uwsgi_log("pcre (study) error: %s\n", errstr);
- exit(1);
+ return -1;
}
+ return 0;
}
@@ -26,32 +28,4 @@ int uwsgi_regexp_match(pcre *pattern, pcre_extra *pattern_extra, char *subject,
return pcre_exec((const pcre*)pattern, (const pcre_extra *)pattern_extra, subject, length, 0, 0, NULL, 0 );
}
-/*
-
-void uwsgi_regexp_match(regexp, what) {
-
- int ret,i;
-
- for(i=0;i<uwsgi->nroutes;i++) {
-
- ret = pcre_exec(ur->pattern, ur->pattern_extra, wsgi_req->path_info, wsgi_req->path_info_len, 0, 0, wsgi_req->ovector, (ur->args+1)*3 );
-
- if (ret >= 0) {
- if (ur->action) {
- ur->action(uwsgi, wsgi_req, ur);
- }
- else {
- uwsgi_route_action_wsgi(uwsgi, wsgi_req, ur);
- }
- }
-
- // TODO check for errors if < 0 && != NO_MATCH
- }
-
- return;
-}
-
-*/
-
-
#endif
50 subscription.c
View
@@ -19,16 +19,32 @@
struct uwsgi_subscribe_slot *uwsgi_get_subscribe_slot(struct uwsgi_subscribe_slot **slot, char *key, uint16_t keylen, int regexp) {
struct uwsgi_subscribe_slot *current_slot = *slot;
+#ifdef UWSGI_PCRE
+ int match;
+#endif
if (keylen > 0xff) return NULL;
while(current_slot) {
+#ifdef UWSGI_PCRE
+ match = 0;
if (regexp) {
+ if (uwsgi_regexp_match(current_slot->pattern, current_slot->pattern_extra, key, keylen)) {
+ match = 1;
+ }
}
else {
+#endif
if (!uwsgi_strncmp(key, keylen, current_slot->key, current_slot->keylen)) {
- // auto optimization
- if (current_slot->prev) {
+#ifdef UWSGI_PCRE
+ match = 1;
+ }
+ }
+
+ if (match) {
+#endif
+ // auto optimization
+ if (current_slot->prev) {
if (current_slot->hits > current_slot->prev->hits) {
struct uwsgi_subscribe_slot *slot_parent = current_slot->prev->prev, *slot_prev = current_slot->prev;
if (slot_parent) {
@@ -44,10 +60,9 @@ struct uwsgi_subscribe_slot *uwsgi_get_subscribe_slot(struct uwsgi_subscribe_slo
current_slot->next = slot_prev;
current_slot->prev = slot_parent;
- }
- }
- return current_slot;
- }
+ }
+ }
+ return current_slot;
}
current_slot = current_slot->next;
}
@@ -88,7 +103,7 @@ void uwsgi_remove_subscribe_node(struct uwsgi_subscribe_slot **slot, struct uwsg
struct uwsgi_subscribe_slot *prev_slot = node_slot->prev;
struct uwsgi_subscribe_slot *next_slot = node_slot->next;
- // avoid race conditions
+ // over-engineering to avoid race conditions
node->len = 0;
if (node == node_slot->nodes) {
@@ -116,6 +131,15 @@ void uwsgi_remove_subscribe_node(struct uwsgi_subscribe_slot **slot, struct uwsg
next_slot->prev = prev_slot;
}
+#ifdef UWSGI_PCRE
+ if (node_slot->pattern) {
+ pcre_free(node_slot->pattern);
+ }
+ if (node_slot->pattern_extra) {
+ pcre_free(node_slot->pattern_extra);
+ }
+#endif
+
free(node_slot);
// am i the only slot ?
if (!prev_slot && !next_slot) {
@@ -167,9 +191,21 @@ struct uwsgi_subscribe_node *uwsgi_add_subscribe_node(struct uwsgi_subscribe_slo
current_slot = uwsgi_malloc(sizeof(struct uwsgi_subscribe_slot));
current_slot->keylen = usr->keylen;
memcpy(current_slot->key, usr->key, usr->keylen);
+ current_slot->key[usr->keylen] = 0;
current_slot->hits = 0;
current_slot->rr = 0;
+#ifdef UWSGI_PCRE
+ current_slot->pattern = NULL;
+ current_slot->pattern_extra = NULL;
+ if (regexp) {
+ if (uwsgi_regexp_build(current_slot->key, &current_slot->pattern, &current_slot->pattern_extra)) {
+ free(current_slot);
+ return NULL;
+ }
+ }
+#endif
+
current_slot->nodes = uwsgi_malloc(sizeof(struct uwsgi_subscribe_node));
current_slot->nodes->slot = current_slot;
current_slot->nodes->len = usr->address_len;
7 uwsgi.h
View
@@ -691,7 +691,7 @@ struct uwsgi_plugin {
#ifdef UWSGI_PCRE
#include <pcre.h>
-void uwsgi_regexp_build(char *re, pcre **pattern, pcre_extra **pattern_extra);
+int uwsgi_regexp_build(char *re, pcre **pattern, pcre_extra **pattern_extra);
int uwsgi_regexp_match(pcre *pattern, pcre_extra *pattern_extra, char *subject, int length);
#endif
@@ -2423,6 +2423,11 @@ struct uwsgi_subscribe_slot {
char key[0xff];
uint16_t keylen;
+#ifdef UWSGI_PCRE
+ pcre *pattern;
+ pcre_extra *pattern_extra;
+#endif
+
uint64_t hits;
// used for round robin
Please sign in to comment.
Something went wrong with that request. Please try again.