fixed file monitor and timers on OSX

This commit is contained in:
roberto@mrspurr
2010-12-19 14:58:01 +01:00
parent fca3c51351
commit 07a87bdff3
5 changed files with 74 additions and 14 deletions
+58 -4
View File
@@ -128,18 +128,49 @@ int event_queue_wait(int eq, int timeout, int *interesting_fd) {
#endif
#ifdef UWSGI_EVENT_FILEMONITOR_USE_KQUEUE
int event_queue_add_file_monitor(int eq, int fd) {
int event_queue_add_file_monitor(int eq, char *filename, int *id) {
struct kevent kev;
int fd = open(filename, O_RDONLY);
if (fd < 0) {
uwsgi_error("open()");
return -1;
}
EV_SET(&kev, fd, EVFILT_VNODE, EV_ADD|EV_CLEAR, NOTE_WRITE|NOTE_DELETE|NOTE_EXTEND|NOTE_ATTRIB|NOTE_RENAME|NOTE_REVOKE, 0, 0);
if (kevent(eq, &kev, 1, NULL, 0, NULL) < 0) {
uwsgi_error("kevent()");
return -1;
}
*id = fd;
return 0;
return fd;
}
struct uwsgi_fmon *event_queue_ack_file_monitor(int id, void hook(char *, uint32_t, char *)) {
int i;
struct uwsgi_fmon *uf = NULL;
for(i=0;i<uwsgi.files_monitored_cnt;i++) {
if (uwsgi.files_monitored[i].registered) {
if (uwsgi.files_monitored[i].fd == id) {
if (hook) {
hook(uwsgi.files_monitored[i].filename, 0, NULL);
}
else {
uf = &uwsgi.files_monitored[i];
}
}
}
}
return uf;
}
#endif
#ifdef UWSGI_EVENT_FILEMONITOR_USE_INOTIFY
@@ -306,7 +337,11 @@ struct uwsgi_timer *event_queue_ack_timer(int id, void hook(int ,int)) { return
#ifdef UWSGI_EVENT_TIMER_USE_KQUEUE
int event_queue_add_timer(int eq, int *id, int sec) {
static int timer_id = 0xffffff00;
struct kevent kev;
*id = timer_id ;
timer_id++;
EV_SET(&kev, *id, EVFILT_TIMER, EV_ADD, 0, sec*1000, 0);
if (kevent(eq, &kev, 1, NULL, 0, NULL) < 0) {
@@ -314,8 +349,27 @@ int event_queue_add_timer(int eq, int *id, int sec) {
return -1;
}
return 0;
return *id;
}
void event_queue_ack_timer(int id) {}
struct uwsgi_timer *event_queue_ack_timer(int id, void hook(int ,int)) {
int i;
struct uwsgi_timer *ut = NULL;
for(i=0;i<uwsgi.timers_cnt;i++) {
if (uwsgi.timers[i].registered) {
if (uwsgi.timers[i].id == id) {
ut = &uwsgi.timers[i];
}
}
}
if (hook) {
hook(ut->value, ut->id);
}
return ut;
}
#endif
-7
View File
@@ -195,13 +195,6 @@ void master_loop(char **argv, char **environ) {
}
#endif
// add a fake timer
/*
int fake_timer = 0xFFFF;
event_queue_add_timer(master_queue, &fake_timer, 5);
*/
// add unregistered file monitors
for(i=0;i<uwsgi.files_monitored_cnt;i++) {
-1
View File
@@ -168,7 +168,6 @@ PyObject *py_uwsgi_signal(PyObject * self, PyObject * args) {
// am i the master ?
if (uwsgi.mywid == 0) {
uwsgi_log("i am the master !!!\n");
register_signal(uwsgi_signal, payload);
goto done;
}
-2
View File
@@ -4,8 +4,6 @@ extern struct uwsgi_server uwsgi;
int register_signal(uint8_t sig, char *payload) {
uwsgi_log("SIGNAL %d %s\n", sig, payload);
switch(sig) {
case 10:
+16
View File
@@ -0,0 +1,16 @@
import uwsgi
# send a raw signal to register with file_monitor subsystem
uwsgi.signal(10, "/tmp/topolino")
uwsgi.signal(10, "/tmp")
uwsgi.signal(10, "/root")
# send a raw signal to register with timer subsystem
uwsgi.signal(11, "3")
uwsgi.signal(11, "4")
uwsgi.signal(11, "8")
def application(e, s):
s('200 Ok', [('Content-Type', 'text/html')])
return "<h1>Hello World</h1>"