0
* License. See README file for details.
0
@@ -38,11 +40,27 @@ struct ev_idle idle_watcher;
0
# define RSTRING_LEN(s) (RSTRING(s)->len)
0
+void attach_idle_watcher()
0
+ if(!ev_is_active(&idle_watcher)) {
0
+ ev_idle_start (loop, &idle_watcher);
0
+void detach_idle_watcher()
0
+ ev_idle_stop(loop, &idle_watcher);
0
void request_cb(ebb_client *client, void *data)
0
VALUE waiting_clients = (VALUE)data;
0
VALUE rb_client = Data_Wrap_Struct(cClient, 0, 0, client);
0
rb_ary_push(waiting_clients, rb_client);
0
+ attach_idle_watcher();
0
VALUE server_listen_on_port(VALUE _, VALUE port)
0
@@ -53,33 +71,19 @@ VALUE server_listen_on_port(VALUE _, VALUE port)
0
-oneshot_timeout (struct ev_loop *loop, struct ev_timer *w, int revents) {;}
0
idle_cb (struct ev_loop *loop, struct ev_idle *w, int revents) {
0
- int running_clients = FALSE;
0
- for(i = 0; i < EBB_MAX_CLIENTS; i++)
0
- if(server->clients[i].open) {
0
- running_clients = TRUE;
0
- if(!running_clients) {
0
- struct timeval tv = { tv_sec: 1, tv_usec: 0 };
0
- FD_SET(server->fd, &fds);
0
- /* sit in ruby thread select for a second when there are no connections */
0
- // printf("enter select()\n");
0
- rb_thread_select(server->fd+1, &fds, &fds, &fds, &tv);
0
- // printf("leave select()\n");
0
+ if(rb_thread_alone()) {
0
+ detach_idle_watcher();
0
VALUE server_process_connections(VALUE _)
0
- ev_loop(loop, EVLOOP_NONBLOCK);
0
+ ev_loop(loop, EVLOOP_ONESHOT);
0
@@ -267,11 +271,8 @@ void Init_ebb_ext()
0
/* initialize ebb_server */
0
loop = ev_default_loop (0);
0
- ev_idle_init (&idle_watcher, idle_cb);
0
- ev_idle_start (loop, &idle_watcher);
0
+ ev_idle_init (&idle_watcher, idle_cb);
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.