0
@@ -40,7 +40,7 @@ struct ev_idle idle_watcher;
0
# define RSTRING_LEN(s) (RSTRING(s)->len)
0
-void attach_idle_watcher()
0
+static void attach_idle_watcher()
0
if(!ev_is_active(&idle_watcher)) {
0
ev_idle_start (loop, &idle_watcher);
0
@@ -49,12 +49,20 @@ void attach_idle_watcher()
0
-void detach_idle_watcher()
0
+static void detach_idle_watcher()
0
ev_idle_stop(loop, &idle_watcher);
0
+static int clients_in_use_p()
0
+ for(i = 0; i < EBB_MAX_CLIENTS; i++)
0
+ if(server->clients[i].in_use) return TRUE;
0
void request_cb(ebb_client *client, void *data)
0
VALUE waiting_clients = (VALUE)data;
0
@@ -72,10 +80,21 @@ VALUE server_listen_on_port(VALUE _, VALUE port)
0
idle_cb (struct ev_loop *loop, struct ev_idle *w, int revents) {
0
- if(rb_thread_alone()) {
0
- detach_idle_watcher();
0
+ if(clients_in_use_p()) {
0
+ } else if(!rb_thread_alone()) {
0
+ /* if you have another long running thread running besides the ones used
0
+ * for the webapp's requests you will run into performance problems in
0
+ * ruby 1.8.x because rb_thread_select is slow.
0
+ * (Don't worry - you're probably not doing this.)
0
+ struct timeval tv = { tv_sec: 0, tv_usec: 50000 };
0
+ FD_ZERO(&server_fd_set);
0
+ FD_SET(server->fd, &server_fd_set);
0
+ rb_thread_select(server->fd+1, &server_fd_set, 0, 0, &tv);
0
+ detach_idle_watcher();
0
@@ -273,6 +292,8 @@ void Init_ebb_ext()
0
loop = ev_default_loop (0);
0
ev_idle_init (&idle_watcher, idle_cb);
0
+ attach_idle_watcher();
0
server = ebb_server_alloc();
0
VALUE waiting_clients = rb_ary_new();
0
rb_iv_set(mFFI, "@waiting_clients", waiting_clients);
Comments
No one has commented yet.