Commit 511d46d7 authored by Denis Bilenko's avatar Denis Bilenko

add async and child watchers

- also use 'def' instead of 'cpdef' for watcher methods on loop
there's no need for fast method to create a watcher since in C you can use libev directly
parent 459fe269
......@@ -2,13 +2,15 @@
static void gevent_callback_##WATCHER_LC(struct ev_loop *, void *, int);
#define DEFINE_CALLBACKS \
DEFINE_CALLBACK(io, IO); \
DEFINE_CALLBACK(timer, Timer); \
DEFINE_CALLBACK(signal, Signal); \
DEFINE_CALLBACK(idle, Idle); \
#define DEFINE_CALLBACKS \
DEFINE_CALLBACK(io, IO); \
DEFINE_CALLBACK(timer, Timer); \
DEFINE_CALLBACK(signal, Signal); \
DEFINE_CALLBACK(idle, Idle); \
DEFINE_CALLBACK(prepare, Prepare); \
DEFINE_CALLBACK(fork, Fork);
DEFINE_CALLBACK(fork, Fork); \
DEFINE_CALLBACK(async, Async); \
DEFINE_CALLBACK(child, Child);
DEFINE_CALLBACKS
......
......@@ -21,6 +21,8 @@ cdef extern from "callbacks.h":
void gevent_callback_idle(libev.ev_loop, void*, int)
void gevent_callback_prepare(libev.ev_loop, void*, int)
void gevent_callback_fork(libev.ev_loop, void*, int)
void gevent_callback_async(libev.ev_loop, void*, int)
void gevent_callback_child(libev.ev_loop, void*, int)
void gevent_signal_check(libev.ev_loop, void*, int)
void gevent_periodic_signal_check(libev.ev_loop, void*, int)
......@@ -354,25 +356,31 @@ cdef public class loop [object PyGeventLoopObject, type PyGeventLoop_Type]:
return self._ptr.activecnt
ENDIF()
cpdef io(self, int fd, int events):
def io(self, int fd, int events):
return io(self, fd, events)
cpdef timer(self, double after, double repeat=0.0):
def timer(self, double after, double repeat=0.0):
return timer(self, after, repeat)
cpdef signal(self, int signum):
def signal(self, int signum):
return signal(self, signum)
cpdef idle(self):
def idle(self):
return idle(self)
cpdef prepare(self):
def prepare(self):
return prepare(self)
cpdef fork(self):
def fork(self):
return fork(self)
cpdef callback(self):
def async(self):
return async(self)
def child(self, int pid, bint trace=0):
return child(self, pid, trace)
def callback(self):
return callback(self)
def run_callback(self, func, *args):
......@@ -574,6 +582,21 @@ cdef public class fork(watcher) [object PyGeventForkObject, type PyGeventFork_Ty
INIT(fork)
cdef public class async(watcher) [object PyGeventAsyncObject, type PyGeventAsync_Type]:
WATCHER(async)
INIT(async)
cdef public class child(watcher) [object PyGeventChildObject, type PyGeventChild_Type]:
WATCHER(child)
INIT(child, ``, int pid, bint trace=0'', ``, pid, trace'')
cdef public class callback(watcher) [object PyGeventCallbackObject, type PyGeventCallback_Type]:
"""Pseudo-watcher used to execute a callback in the loop as soon as possible."""
......
......@@ -3,3 +3,13 @@
#else
#include "ev.h"
#endif
#if (!EV_CHILD_ENABLE)
/* When ev_child is not available (Windows), we should not define gevent.core.child and gevent.core.loop.child().
* Temporarily defining no-op functions since there's no easy way to do optional methods with Cython. */
void ev_child_start(void*, void*);
void ev_child_start(void* a, void* b) {}
void ev_child_stop(void*, void*);
void ev_child_stop(void* a, void* b) {}
#endif
......@@ -76,6 +76,14 @@ cdef extern from "libev.h":
struct ev_fork:
pass
struct ev_async:
pass
struct ev_child:
int pid
int rpid
int rstatus
int ev_version_major()
int ev_version_minor()
......@@ -116,6 +124,14 @@ cdef extern from "libev.h":
void ev_fork_start(ev_loop*, ev_fork*)
void ev_fork_stop(ev_loop*, ev_fork*)
void ev_async_init(ev_async*, void* callback)
void ev_async_start(ev_loop*, ev_async*)
void ev_async_stop(ev_loop*, ev_async*)
void ev_child_init(ev_child*, void* callback, int, int)
void ev_child_start(ev_loop*, ev_child*)
void ev_child_stop(ev_loop*, ev_child*)
ev_loop* ev_default_loop(unsigned int flags)
ev_loop* ev_loop_new(unsigned int flags)
void ev_loop_destroy(ev_loop*)
......
......@@ -52,9 +52,7 @@ if os.path.exists('libev'):
('EV_CHECK_ENABLE', '0'),
('EV_CLEANUP_ENABLE', '0'),
('EV_EMBED_ENABLE', '0'),
('EV_ASYNC_ENABLE', '0'),
("EV_PERIODIC_ENABLE", '0'),
("EV_CHILD_ENABLE", '0')]
("EV_PERIODIC_ENABLE", '0')]
#CORE.gcc_options = ['-Wno-unused-variable', '-Wno-unused-result'] # disable warnings from ev.c
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment