public
Description: New and ultra-turbo-crazy-fast backend for Thin
Homepage: http://code.macournoyer.com/thin/
Clone URL: git://github.com/macournoyer/thin-turbo.git
Search Repo:
Remove "watch" macro and init watcher when connection is started
macournoyer (author)
Wed Apr 30 20:34:00 -0700 2008
commit  75715402dde0955023b07c4ae51a465f2a85ba17
tree    a361013d88f1028eff9fc4122f2e0389a811a07f
parent  0f7afa9c06008d9467a62977661efe8ceea74c1b
...
89
90
91
92
 
 
93
94
95
...
103
104
105
 
 
106
107
108
...
89
90
91
 
92
93
94
95
96
...
104
105
106
107
108
109
110
111
0
@@ -89,7 +89,8 @@ VALUE backend_listen_on_port(VALUE self, VALUE address, VALUE port)
0
     rb_sys_fail("listen");
0
   
0
   /* initialise watchers */
0
- watch(backend, backend_accept_cb, accept, EV_READ);
0
+ backend->accept_watcher.data = backend;
0
+ ev_io_init(&backend->accept_watcher, backend_accept_cb, backend->fd, EV_READ);
0
   
0
   backend->prepare_watcher.data = backend;
0
   ev_prepare_init(&backend->prepare_watcher, backend_prepare_cb);
0
@@ -103,6 +104,8 @@ VALUE backend_listen_on_port(VALUE self, VALUE address, VALUE port)
0
   
0
   backend->open = 1;
0
   
0
+ ev_io_start(backend->loop, &backend->accept_watcher);
0
+
0
   return Qtrue;
0
 }
0
 
...
38
39
40
41
 
42
43
44
...
107
108
109
 
 
110
111
112
 
 
 
 
113
 
114
115
116
...
126
127
128
129
130
 
 
131
132
133
...
38
39
40
 
41
42
43
44
...
107
108
109
110
111
112
 
 
113
114
115
116
117
118
119
120
121
...
131
132
133
 
 
134
135
136
137
138
0
@@ -38,7 +38,7 @@ static void connection_writable_cb(EV_P_ struct ev_io *watcher, int revents)
0
 
0
 void connection_watch_writable(connection_t *c)
0
 {
0
- watch(c, connection_writable_cb, write, EV_WRITE);
0
+ ev_io_start(c->loop, &c->write_watcher);
0
 }
0
 
0
 static void connection_readable_cb(EV_P_ struct ev_io *watcher, int revents)
0
@@ -107,10 +107,15 @@ void connection_start(backend_t *backend, int fd, struct sockaddr_in remote_addr
0
   c->parser.data = c;
0
   
0
   /* init libev stuff */
0
+ c->read_watcher.data = c;
0
+ c->write_watcher.data = c;
0
   c->timeout_watcher.data = c;
0
- watch(c, connection_readable_cb, read, EV_READ);
0
- /* timeout watcher, close connection when peer not responding */
0
+ ev_io_init(&c->read_watcher, connection_readable_cb, c->fd, EV_READ);
0
+ ev_io_init(&c->write_watcher, connection_writable_cb, c->fd, EV_WRITE);
0
+
0
+ /* start event watchers */
0
   ev_timer_start(c->loop, &c->timeout_watcher);
0
+ ev_io_start(c->loop, &c->read_watcher);
0
 }
0
 
0
 void connection_error(connection_t *c, const char *msg)
0
@@ -126,8 +131,8 @@ void connection_errno(connection_t *c)
0
 
0
 void connection_close(connection_t *c)
0
 {
0
- unwatch(c, read);
0
- unwatch(c, write);
0
+ ev_io_stop(c->loop, &c->read_watcher);
0
+ ev_io_stop(c->loop, &c->write_watcher);
0
   ev_timer_stop(c->loop, &c->timeout_watcher);
0
 
0
   close(c->fd);
...
52
53
54
55
 
56
57
58
...
52
53
54
 
55
56
57
58
0
@@ -52,7 +52,7 @@ void request_parse(connection_t *c, char *buf, int len)
0
   
0
   /* request fully received */
0
   if (http_parser_is_finished(&c->parser) && c->read_buffer.len >= c->content_length) {
0
- unwatch(c, read);
0
+ ev_io_stop(c->loop, &c->read_watcher);
0
     
0
     /* assign env[rack.input] */
0
     rb_hash_aset(c->env, sRackInput, buffer_to_ruby_obj(&c->read_buffer));
...
104
105
106
107
108
109
110
111
112
113
114
115
116
117
...
104
105
106
 
 
 
 
 
 
 
 
107
108
109
0
@@ -104,14 +104,6 @@ struct backend_s {
0
 };
0
 
0
 /* libev helpers */
0
-#define watch(conn, cb, event, ev_event) \
0
- ev_io_init(&conn->event##_watcher, cb, conn->fd, ev_event); \
0
- conn->event##_watcher.data = conn; \
0
- ev_io_start(conn->loop, &conn->event##_watcher);
0
-
0
-#define unwatch(conn, event) \
0
- ev_io_stop(conn->backend->loop, &conn->event##_watcher);
0
-
0
 #define get_ev_data(type, w, event) \
0
   (type##_t *) w->data; \
0
   assert(&((type##_t *)w->data)->event##_watcher == w);

Comments

    No one has commented yet.