rev 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README +45 -9
- data/doc/rdoc/classes/Rev.html +368 -0
- data/doc/rdoc/classes/Rev.src/M000001.html +28 -0
- data/doc/rdoc/classes/Rev.src/M000002.html +35 -0
- data/doc/rdoc/classes/Rev.src/M000003.html +24 -0
- data/doc/rdoc/classes/Rev.src/M000004.html +28 -0
- data/doc/rdoc/classes/Rev.src/M000005.html +27 -0
- data/doc/rdoc/classes/Rev.src/M000006.html +33 -0
- data/doc/rdoc/classes/Rev.src/M000007.html +43 -0
- data/doc/rdoc/classes/Rev.src/M000008.html +16 -0
- data/doc/rdoc/classes/Rev/Buffer.html +354 -0
- data/doc/rdoc/classes/Rev/Buffer.src/M000019.html +17 -0
- data/doc/rdoc/classes/Rev/Buffer.src/M000020.html +29 -0
- data/doc/rdoc/classes/Rev/Buffer.src/M000021.html +27 -0
- data/doc/rdoc/classes/Rev/Buffer.src/M000022.html +27 -0
- data/doc/rdoc/classes/Rev/Buffer.src/M000023.html +31 -0
- data/doc/rdoc/classes/Rev/Buffer.src/M000024.html +31 -0
- data/doc/rdoc/classes/Rev/Buffer.src/M000025.html +30 -0
- data/doc/rdoc/classes/Rev/Buffer.src/M000026.html +50 -0
- data/doc/rdoc/classes/Rev/Buffer.src/M000027.html +22 -0
- data/doc/rdoc/classes/Rev/Buffer.src/M000028.html +24 -0
- data/doc/rdoc/classes/Rev/Buffer.src/M000029.html +24 -0
- data/doc/rdoc/classes/Rev/BufferedIO.html +397 -0
- data/doc/rdoc/classes/Rev/BufferedIO.src/M000095.html +23 -0
- data/doc/rdoc/classes/Rev/BufferedIO.src/M000096.html +16 -0
- data/doc/rdoc/classes/Rev/BufferedIO.src/M000097.html +16 -0
- data/doc/rdoc/classes/Rev/BufferedIO.src/M000098.html +16 -0
- data/doc/rdoc/classes/Rev/BufferedIO.src/M000099.html +18 -0
- data/doc/rdoc/classes/Rev/BufferedIO.src/M000100.html +18 -0
- data/doc/rdoc/classes/Rev/BufferedIO.src/M000101.html +23 -0
- data/doc/rdoc/classes/Rev/BufferedIO.src/M000102.html +18 -0
- data/doc/rdoc/classes/Rev/BufferedIO.src/M000103.html +20 -0
- data/doc/rdoc/classes/Rev/BufferedIO.src/M000104.html +24 -0
- data/doc/rdoc/classes/Rev/BufferedIO.src/M000105.html +23 -0
- data/doc/rdoc/classes/Rev/BufferedIO.src/M000106.html +22 -0
- data/doc/rdoc/classes/Rev/BufferedIO.src/M000107.html +29 -0
- data/doc/rdoc/classes/Rev/BufferedIO/Writer.html +154 -0
- data/doc/rdoc/classes/Rev/BufferedIO/Writer.src/M000108.html +19 -0
- data/doc/rdoc/classes/Rev/BufferedIO/Writer.src/M000109.html +18 -0
- data/doc/rdoc/classes/Rev/DNSResolver.html +401 -0
- data/doc/rdoc/classes/Rev/DNSResolver.src/M000124.html +25 -0
- data/doc/rdoc/classes/Rev/DNSResolver.src/M000125.html +29 -0
- data/doc/rdoc/classes/Rev/DNSResolver.src/M000126.html +20 -0
- data/doc/rdoc/classes/Rev/DNSResolver.src/M000127.html +19 -0
- data/doc/rdoc/classes/Rev/DNSResolver.src/M000128.html +16 -0
- data/doc/rdoc/classes/Rev/DNSResolver.src/M000129.html +16 -0
- data/doc/rdoc/classes/Rev/DNSResolver.src/M000131.html +19 -0
- data/doc/rdoc/classes/Rev/DNSResolver.src/M000132.html +21 -0
- data/doc/rdoc/classes/Rev/DNSResolver.src/M000133.html +27 -0
- data/doc/rdoc/classes/Rev/DNSResolver.src/M000134.html +28 -0
- data/doc/rdoc/classes/Rev/DNSResolver.src/M000135.html +55 -0
- data/doc/rdoc/classes/Rev/DNSResolver/Timeout.html +154 -0
- data/doc/rdoc/classes/Rev/DNSResolver/Timeout.src/M000136.html +20 -0
- data/doc/rdoc/classes/Rev/DNSResolver/Timeout.src/M000137.html +22 -0
- data/doc/rdoc/classes/Rev/HttpChunkHeader.html +156 -0
- data/doc/rdoc/classes/Rev/HttpChunkHeader.src/M000031.html +19 -0
- data/doc/rdoc/classes/Rev/HttpClient.html +460 -0
- data/doc/rdoc/classes/Rev/HttpClient.src/M000042.html +18 -0
- data/doc/rdoc/classes/Rev/HttpClient.src/M000043.html +27 -0
- data/doc/rdoc/classes/Rev/HttpClient.src/M000044.html +24 -0
- data/doc/rdoc/classes/Rev/HttpClient.src/M000045.html +19 -0
- data/doc/rdoc/classes/Rev/HttpClient.src/M000046.html +17 -0
- data/doc/rdoc/classes/Rev/HttpClient.src/M000047.html +19 -0
- data/doc/rdoc/classes/Rev/HttpClient.src/M000048.html +18 -0
- data/doc/rdoc/classes/Rev/HttpClient.src/M000049.html +18 -0
- data/doc/rdoc/classes/Rev/HttpClient.src/M000050.html +19 -0
- data/doc/rdoc/classes/Rev/HttpClient.src/M000051.html +19 -0
- data/doc/rdoc/classes/Rev/HttpClient.src/M000052.html +19 -0
- data/doc/rdoc/classes/Rev/HttpClient.src/M000053.html +41 -0
- data/doc/rdoc/classes/Rev/HttpClient.src/M000054.html +18 -0
- data/doc/rdoc/classes/Rev/HttpClient.src/M000055.html +34 -0
- data/doc/rdoc/classes/Rev/HttpEncoding.html +310 -0
- data/doc/rdoc/classes/Rev/HttpEncoding.src/M000009.html +20 -0
- data/doc/rdoc/classes/Rev/HttpEncoding.src/M000010.html +20 -0
- data/doc/rdoc/classes/Rev/HttpEncoding.src/M000011.html +18 -0
- data/doc/rdoc/classes/Rev/HttpEncoding.src/M000012.html +18 -0
- data/doc/rdoc/classes/Rev/HttpEncoding.src/M000013.html +18 -0
- data/doc/rdoc/classes/Rev/HttpEncoding.src/M000014.html +19 -0
- data/doc/rdoc/classes/Rev/HttpEncoding.src/M000015.html +18 -0
- data/doc/rdoc/classes/Rev/HttpEncoding.src/M000016.html +18 -0
- data/doc/rdoc/classes/Rev/HttpEncoding.src/M000017.html +22 -0
- data/doc/rdoc/classes/Rev/HttpEncoding.src/M000018.html +18 -0
- data/doc/rdoc/classes/Rev/HttpResponseHeader.html +219 -0
- data/doc/rdoc/classes/Rev/HttpResponseHeader.src/M000032.html +18 -0
- data/doc/rdoc/classes/Rev/HttpResponseHeader.src/M000033.html +18 -0
- data/doc/rdoc/classes/Rev/HttpResponseHeader.src/M000034.html +18 -0
- data/doc/rdoc/classes/Rev/IOWatcher.html +285 -0
- data/doc/rdoc/classes/Rev/IOWatcher.src/M000079.html +17 -0
- data/doc/rdoc/classes/Rev/IOWatcher.src/M000080.html +27 -0
- data/doc/rdoc/classes/Rev/IOWatcher.src/M000081.html +26 -0
- data/doc/rdoc/classes/Rev/IOWatcher.src/M000082.html +27 -0
- data/doc/rdoc/classes/Rev/IOWatcher.src/M000083.html +27 -0
- data/doc/rdoc/classes/Rev/IOWatcher.src/M000084.html +24 -0
- data/doc/rdoc/classes/Rev/IOWatcher.src/M000085.html +25 -0
- data/doc/rdoc/classes/Rev/Listener.html +207 -0
- data/doc/rdoc/classes/Rev/Listener.src/M000065.html +19 -0
- data/doc/rdoc/classes/Rev/Listener.src/M000066.html +19 -0
- data/doc/rdoc/classes/Rev/Listener.src/M000067.html +16 -0
- data/doc/rdoc/classes/Rev/Listener.src/M000068.html +18 -0
- data/doc/rdoc/classes/Rev/Loop.html +395 -0
- data/doc/rdoc/classes/Rev/Loop.src/M000070.html +25 -0
- data/doc/rdoc/classes/Rev/Loop.src/M000071.html +45 -0
- data/doc/rdoc/classes/Rev/Loop.src/M000072.html +18 -0
- data/doc/rdoc/classes/Rev/Loop.src/M000073.html +23 -0
- data/doc/rdoc/classes/Rev/Loop.src/M000074.html +19 -0
- data/doc/rdoc/classes/Rev/Loop.src/M000075.html +17 -0
- data/doc/rdoc/classes/Rev/Loop.src/M000076.html +27 -0
- data/doc/rdoc/classes/Rev/Loop.src/M000077.html +32 -0
- data/doc/rdoc/classes/Rev/Loop.src/M000078.html +32 -0
- data/doc/rdoc/classes/Rev/Server.html +164 -0
- data/doc/rdoc/classes/Rev/Server.src/M000121.html +32 -0
- data/doc/rdoc/classes/Rev/Server.src/M000122.html +20 -0
- data/doc/rdoc/classes/Rev/Socket.html +213 -0
- data/doc/rdoc/classes/Rev/Socket.src/M000035.html +21 -0
- data/doc/rdoc/classes/Rev/Socket.src/M000036.html +25 -0
- data/doc/rdoc/classes/Rev/Socket.src/M000037.html +16 -0
- data/doc/rdoc/classes/Rev/Socket.src/M000038.html +16 -0
- data/doc/rdoc/classes/Rev/Socket/Connector.html +154 -0
- data/doc/rdoc/classes/Rev/Socket/Connector.src/M000040.html +19 -0
- data/doc/rdoc/classes/Rev/Socket/Connector.src/M000041.html +28 -0
- data/doc/rdoc/classes/Rev/TCPListener.html +161 -0
- data/doc/rdoc/classes/Rev/TCPListener.src/M000069.html +23 -0
- data/doc/rdoc/classes/Rev/TCPServer.html +147 -0
- data/doc/rdoc/classes/Rev/TCPServer.src/M000123.html +20 -0
- data/doc/rdoc/classes/Rev/TCPSocket.html +233 -0
- data/doc/rdoc/classes/Rev/TCPSocket.src/M000056.html +20 -0
- data/doc/rdoc/classes/Rev/TCPSocket.src/M000057.html +34 -0
- data/doc/rdoc/classes/Rev/TCPSocket.src/M000058.html +24 -0
- data/doc/rdoc/classes/Rev/TCPSocket.src/M000059.html +18 -0
- data/doc/rdoc/classes/Rev/TCPSocket/TCPConnectResolver.html +171 -0
- data/doc/rdoc/classes/Rev/TCPSocket/TCPConnectResolver.src/M000060.html +19 -0
- data/doc/rdoc/classes/Rev/TCPSocket/TCPConnectResolver.src/M000061.html +27 -0
- data/doc/rdoc/classes/Rev/TCPSocket/TCPConnectResolver.src/M000062.html +23 -0
- data/doc/rdoc/classes/Rev/TCPSocket/TCPConnectSocket.html +154 -0
- data/doc/rdoc/classes/Rev/TCPSocket/TCPConnectSocket.src/M000063.html +25 -0
- data/doc/rdoc/classes/Rev/TCPSocket/TCPConnectSocket.src/M000064.html +23 -0
- data/doc/rdoc/classes/Rev/TimerWatcher.html +288 -0
- data/doc/rdoc/classes/Rev/TimerWatcher.src/M000086.html +17 -0
- data/doc/rdoc/classes/Rev/TimerWatcher.src/M000087.html +27 -0
- data/doc/rdoc/classes/Rev/TimerWatcher.src/M000088.html +26 -0
- data/doc/rdoc/classes/Rev/TimerWatcher.src/M000089.html +27 -0
- data/doc/rdoc/classes/Rev/TimerWatcher.src/M000090.html +27 -0
- data/doc/rdoc/classes/Rev/TimerWatcher.src/M000091.html +42 -0
- data/doc/rdoc/classes/Rev/TimerWatcher.src/M000092.html +24 -0
- data/doc/rdoc/classes/Rev/UNIXListener.html +147 -0
- data/doc/rdoc/classes/Rev/UNIXListener.src/M000120.html +18 -0
- data/doc/rdoc/classes/Rev/UNIXServer.html +147 -0
- data/doc/rdoc/classes/Rev/UNIXServer.src/M000030.html +18 -0
- data/doc/rdoc/classes/Rev/UNIXSocket.html +175 -0
- data/doc/rdoc/classes/Rev/UNIXSocket.src/M000093.html +18 -0
- data/doc/rdoc/classes/Rev/UNIXSocket.src/M000094.html +21 -0
- data/doc/rdoc/classes/Rev/Watcher.html +349 -0
- data/doc/rdoc/classes/Rev/Watcher.src/M000110.html +20 -0
- data/doc/rdoc/classes/Rev/Watcher.src/M000111.html +20 -0
- data/doc/rdoc/classes/Rev/Watcher.src/M000112.html +17 -0
- data/doc/rdoc/classes/Rev/Watcher.src/M000113.html +48 -0
- data/doc/rdoc/classes/Rev/Watcher.src/M000114.html +62 -0
- data/doc/rdoc/classes/Rev/Watcher.src/M000115.html +34 -0
- data/doc/rdoc/classes/Rev/Watcher.src/M000116.html +34 -0
- data/doc/rdoc/classes/Rev/Watcher.src/M000117.html +27 -0
- data/doc/rdoc/classes/Rev/Watcher.src/M000118.html +24 -0
- data/doc/rdoc/classes/Rev/Watcher.src/M000119.html +27 -0
- data/doc/rdoc/created.rid +1 -0
- data/doc/rdoc/files/LICENSE.html +165 -0
- data/doc/rdoc/files/README.html +297 -0
- data/doc/rdoc/files/ext/rev/rev_buffer_c.html +101 -0
- data/doc/rdoc/files/ext/rev/rev_ext_c.html +101 -0
- data/doc/rdoc/files/ext/rev/rev_io_watcher_c.html +101 -0
- data/doc/rdoc/files/ext/rev/rev_loop_c.html +101 -0
- data/doc/rdoc/files/ext/rev/rev_timer_watcher_c.html +101 -0
- data/doc/rdoc/files/ext/rev/rev_watcher_c.html +101 -0
- data/doc/rdoc/files/lib/rev/buffered_io_rb.html +101 -0
- data/doc/rdoc/files/lib/rev/dns_resolver_rb.html +101 -0
- data/doc/rdoc/files/lib/rev/http_client_rb.html +101 -0
- data/doc/rdoc/files/lib/rev/io_watcher_rb.html +101 -0
- data/doc/rdoc/files/lib/rev/listener_rb.html +108 -0
- data/doc/rdoc/files/lib/rev/loop_rb.html +101 -0
- data/doc/rdoc/files/lib/rev/server_rb.html +101 -0
- data/doc/rdoc/files/lib/rev/socket_rb.html +109 -0
- data/doc/rdoc/files/lib/rev/timer_watcher_rb.html +101 -0
- data/doc/rdoc/files/lib/rev/watcher_rb.html +101 -0
- data/doc/rdoc/files/lib/rev_rb.html +101 -0
- data/doc/rdoc/fr_class_index.html +52 -0
- data/doc/rdoc/fr_file_index.html +45 -0
- data/doc/rdoc/fr_method_index.html +163 -0
- data/doc/rdoc/index.html +24 -0
- data/doc/rdoc/rdoc-style.css +208 -0
- data/ext/rev/extconf.rb +1 -1
- data/ext/rev/rev.h +0 -1
- data/ext/rev/rev_buffer.c +606 -0
- data/ext/rev/rev_ext.c +1 -0
- data/ext/rev/rev_io_watcher.c +53 -19
- data/ext/rev/rev_loop.c +12 -35
- data/ext/rev/rev_timer_watcher.c +45 -3
- data/ext/rev/rev_watcher.c +13 -1
- data/lib/http11_client.bundle +0 -0
- data/lib/rev.rb +1 -1
- data/lib/rev/buffered_io.rb +25 -22
- data/lib/rev/dns_resolver.rb +31 -14
- data/lib/rev/http_client.rb +88 -91
- data/lib/rev/listener.rb +22 -5
- data/lib/rev/loop.rb +13 -0
- data/lib/rev/server.rb +10 -3
- data/lib/rev/socket.rb +30 -9
- data/lib/rev/watcher.rb +4 -2
- data/lib/rev_ext.bundle +0 -0
- metadata +230 -2
@@ -0,0 +1,48 @@
|
|
1
|
+
<?xml version="1.0" encoding="iso-8859-1"?>
|
2
|
+
<!DOCTYPE html
|
3
|
+
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
4
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
5
|
+
|
6
|
+
<html>
|
7
|
+
<head>
|
8
|
+
<title>attach (Rev::Watcher)</title>
|
9
|
+
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
10
|
+
<link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
|
11
|
+
</head>
|
12
|
+
<body class="standalone-code">
|
13
|
+
<pre>/**
|
14
|
+
* call-seq:
|
15
|
+
* Rev::Watcher.attach(loop) -> Rev::Watcher
|
16
|
+
*
|
17
|
+
* Attach the watcher to the given Rev::Loop. If the watcher is already attached
|
18
|
+
* to a loop, detach it from the old one and attach it to the new one.
|
19
|
+
*/
|
20
|
+
static VALUE Rev_Watcher_attach(VALUE self, VALUE loop)
|
21
|
+
{
|
22
|
+
VALUE loop_watchers, active_watchers;
|
23
|
+
|
24
|
+
loop_watchers = rb_iv_get(loop, "@watchers");
|
25
|
+
|
26
|
+
if(loop_watchers == Qnil) {
|
27
|
+
loop_watchers = rb_ary_new();
|
28
|
+
rb_iv_set(loop, "@watchers", loop_watchers);
|
29
|
+
}
|
30
|
+
|
31
|
+
/* Add us to the loop's array of active watchers. This is mainly done
|
32
|
+
* to keep the VM from garbage collecting watchers that are associated
|
33
|
+
* with a loop (and also lets you see within Ruby which watchers are
|
34
|
+
* associated with a given loop), but isn't really necessary for any
|
35
|
+
* other reason */
|
36
|
+
rb_ary_push(loop_watchers, self);
|
37
|
+
|
38
|
+
active_watchers = rb_iv_get(loop, "@active_watchers");
|
39
|
+
if(active_watchers == Qnil)
|
40
|
+
active_watchers = INT2NUM(1);
|
41
|
+
else
|
42
|
+
active_watchers = INT2NUM(NUM2INT(active_watchers) + 1);
|
43
|
+
rb_iv_set(loop, "@active_watchers", active_watchers);
|
44
|
+
|
45
|
+
return self;
|
46
|
+
}</pre>
|
47
|
+
</body>
|
48
|
+
</html>
|
@@ -0,0 +1,62 @@
|
|
1
|
+
<?xml version="1.0" encoding="iso-8859-1"?>
|
2
|
+
<!DOCTYPE html
|
3
|
+
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
4
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
5
|
+
|
6
|
+
<html>
|
7
|
+
<head>
|
8
|
+
<title>detach (Rev::Watcher)</title>
|
9
|
+
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
10
|
+
<link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
|
11
|
+
</head>
|
12
|
+
<body class="standalone-code">
|
13
|
+
<pre>/**
|
14
|
+
* call-seq:
|
15
|
+
* Rev::Watcher.detach -> Rev::Watcher
|
16
|
+
*
|
17
|
+
* Detach the watcher from its current Rev::Loop.
|
18
|
+
*/
|
19
|
+
static VALUE Rev_Watcher_detach(VALUE self)
|
20
|
+
{
|
21
|
+
struct Rev_Watcher *watcher_data;
|
22
|
+
struct Rev_Loop *loop_data;
|
23
|
+
VALUE loop_watchers;
|
24
|
+
|
25
|
+
int i;
|
26
|
+
|
27
|
+
Data_Get_Struct(self, struct Rev_Watcher, watcher_data);
|
28
|
+
|
29
|
+
if(watcher_data->loop == Qnil)
|
30
|
+
rb_raise(rb_eRuntimeError, "not attached to a loop");
|
31
|
+
|
32
|
+
loop_watchers = rb_iv_get(watcher_data->loop, "@watchers");
|
33
|
+
|
34
|
+
/* Remove us from the loop's array of active watchers. This likely
|
35
|
+
* has negative performance and scalability characteristics as this
|
36
|
+
* isn't an O(1) operation. Hopefully there's a better way... */
|
37
|
+
rb_ary_delete(loop_watchers, self);
|
38
|
+
|
39
|
+
rb_iv_set(
|
40
|
+
watcher_data->loop,
|
41
|
+
"@active_watchers",
|
42
|
+
INT2NUM(NUM2INT(rb_iv_get(watcher_data->loop, "@active_watchers")) - 1)
|
43
|
+
);
|
44
|
+
|
45
|
+
Data_Get_Struct(watcher_data->loop, struct Rev_Loop, loop_data);
|
46
|
+
|
47
|
+
/* Iterate through the events in the loop's event buffer. If there
|
48
|
+
* are any pending events from this watcher, mark them NULL. The
|
49
|
+
* dispatch loop will skip them. This prevents watchers earlier
|
50
|
+
* in the event buffer from detaching others which may have pending
|
51
|
+
* events in the buffer but get garbage collected in the meantime */
|
52
|
+
for(i = 0; i < loop_data->events_received; i++) {
|
53
|
+
if(loop_data->eventbuf[i].watcher == self)
|
54
|
+
loop_data->eventbuf[i].watcher = Qnil;
|
55
|
+
}
|
56
|
+
|
57
|
+
watcher_data->loop = Qnil;
|
58
|
+
|
59
|
+
return self;
|
60
|
+
}</pre>
|
61
|
+
</body>
|
62
|
+
</html>
|
@@ -0,0 +1,34 @@
|
|
1
|
+
<?xml version="1.0" encoding="iso-8859-1"?>
|
2
|
+
<!DOCTYPE html
|
3
|
+
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
4
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
5
|
+
|
6
|
+
<html>
|
7
|
+
<head>
|
8
|
+
<title>enable (Rev::Watcher)</title>
|
9
|
+
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
10
|
+
<link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
|
11
|
+
</head>
|
12
|
+
<body class="standalone-code">
|
13
|
+
<pre>/**
|
14
|
+
* call-seq:
|
15
|
+
* Rev::Watcher.enable -> Rev::Watcher
|
16
|
+
*
|
17
|
+
* Re-enable a watcher which has been temporarily disabled. See the
|
18
|
+
* disable method for a more thorough explanation.
|
19
|
+
*/
|
20
|
+
static VALUE Rev_Watcher_enable(VALUE self)
|
21
|
+
{
|
22
|
+
struct Rev_Watcher *watcher_data;
|
23
|
+
Data_Get_Struct(self, struct Rev_Watcher, watcher_data);
|
24
|
+
|
25
|
+
rb_iv_set(
|
26
|
+
watcher_data->loop,
|
27
|
+
"@active_watchers",
|
28
|
+
INT2NUM(NUM2INT(rb_iv_get(watcher_data->loop, "@active_watchers")) + 1)
|
29
|
+
);
|
30
|
+
|
31
|
+
return self;
|
32
|
+
}</pre>
|
33
|
+
</body>
|
34
|
+
</html>
|
@@ -0,0 +1,34 @@
|
|
1
|
+
<?xml version="1.0" encoding="iso-8859-1"?>
|
2
|
+
<!DOCTYPE html
|
3
|
+
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
4
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
5
|
+
|
6
|
+
<html>
|
7
|
+
<head>
|
8
|
+
<title>disable (Rev::Watcher)</title>
|
9
|
+
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
10
|
+
<link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
|
11
|
+
</head>
|
12
|
+
<body class="standalone-code">
|
13
|
+
<pre>/**
|
14
|
+
* call-seq:
|
15
|
+
* Rev::Watcher.disable -> Rev::Watcher
|
16
|
+
*
|
17
|
+
* Temporarily disable an event watcher which is attached to a loop.
|
18
|
+
* This is useful if you wish to toggle event monitoring on and off.
|
19
|
+
*/
|
20
|
+
static VALUE Rev_Watcher_disable(VALUE self)
|
21
|
+
{
|
22
|
+
struct Rev_Watcher *watcher_data;
|
23
|
+
Data_Get_Struct(self, struct Rev_Watcher, watcher_data);
|
24
|
+
|
25
|
+
rb_iv_set(
|
26
|
+
watcher_data->loop,
|
27
|
+
"@active_watchers",
|
28
|
+
INT2NUM(NUM2INT(rb_iv_get(watcher_data->loop, "@active_watchers")) - 1)
|
29
|
+
);
|
30
|
+
|
31
|
+
return self;
|
32
|
+
}</pre>
|
33
|
+
</body>
|
34
|
+
</html>
|
@@ -0,0 +1,27 @@
|
|
1
|
+
<?xml version="1.0" encoding="iso-8859-1"?>
|
2
|
+
<!DOCTYPE html
|
3
|
+
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
4
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
5
|
+
|
6
|
+
<html>
|
7
|
+
<head>
|
8
|
+
<title>evloop (Rev::Watcher)</title>
|
9
|
+
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
10
|
+
<link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
|
11
|
+
</head>
|
12
|
+
<body class="standalone-code">
|
13
|
+
<pre>/**
|
14
|
+
* call-seq:
|
15
|
+
* Rev::Watcher.evloop -> Rev::Loop
|
16
|
+
*
|
17
|
+
* Return the loop to which we're currently attached
|
18
|
+
*/
|
19
|
+
static VALUE Rev_Watcher_evloop(VALUE self)
|
20
|
+
{
|
21
|
+
struct Rev_Watcher *watcher_data;
|
22
|
+
|
23
|
+
Data_Get_Struct(self, struct Rev_Watcher, watcher_data);
|
24
|
+
return watcher_data->loop;
|
25
|
+
}</pre>
|
26
|
+
</body>
|
27
|
+
</html>
|
@@ -0,0 +1,24 @@
|
|
1
|
+
<?xml version="1.0" encoding="iso-8859-1"?>
|
2
|
+
<!DOCTYPE html
|
3
|
+
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
4
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
5
|
+
|
6
|
+
<html>
|
7
|
+
<head>
|
8
|
+
<title>attached? (Rev::Watcher)</title>
|
9
|
+
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
10
|
+
<link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
|
11
|
+
</head>
|
12
|
+
<body class="standalone-code">
|
13
|
+
<pre>/**
|
14
|
+
* call-seq:
|
15
|
+
* Rev::Watcher.attached? -> Boolean
|
16
|
+
*
|
17
|
+
* Is the watcher currently attached to an event loop?
|
18
|
+
*/
|
19
|
+
static VALUE Rev_Watcher_attached(VALUE self)
|
20
|
+
{
|
21
|
+
return Rev_Watcher_evloop(self) != Qnil;
|
22
|
+
}</pre>
|
23
|
+
</body>
|
24
|
+
</html>
|
@@ -0,0 +1,27 @@
|
|
1
|
+
<?xml version="1.0" encoding="iso-8859-1"?>
|
2
|
+
<!DOCTYPE html
|
3
|
+
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
4
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
5
|
+
|
6
|
+
<html>
|
7
|
+
<head>
|
8
|
+
<title>enabled? (Rev::Watcher)</title>
|
9
|
+
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
10
|
+
<link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
|
11
|
+
</head>
|
12
|
+
<body class="standalone-code">
|
13
|
+
<pre>/**
|
14
|
+
* call-seq:
|
15
|
+
* Rev::Watcher.enabled? -> Boolean
|
16
|
+
*
|
17
|
+
* Is the watcher currently enabled?
|
18
|
+
*/
|
19
|
+
static VALUE Rev_Watcher_enabled(VALUE self)
|
20
|
+
{
|
21
|
+
struct Rev_Watcher *watcher_data;
|
22
|
+
Data_Get_Struct(self, struct Rev_Watcher, watcher_data);
|
23
|
+
|
24
|
+
return watcher_data->enabled ? Qtrue : Qfalse;
|
25
|
+
}</pre>
|
26
|
+
</body>
|
27
|
+
</html>
|
@@ -0,0 +1 @@
|
|
1
|
+
Tue, 15 Jan 2008 01:24:06 -0700
|
@@ -0,0 +1,165 @@
|
|
1
|
+
<?xml version="1.0" encoding="iso-8859-1"?>
|
2
|
+
<!DOCTYPE html
|
3
|
+
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
4
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
5
|
+
|
6
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
7
|
+
<head>
|
8
|
+
<title>File: LICENSE</title>
|
9
|
+
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
10
|
+
<meta http-equiv="Content-Script-Type" content="text/javascript" />
|
11
|
+
<link rel="stylesheet" href=".././rdoc-style.css" type="text/css" media="screen" />
|
12
|
+
<script type="text/javascript">
|
13
|
+
// <![CDATA[
|
14
|
+
|
15
|
+
function popupCode( url ) {
|
16
|
+
window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
|
17
|
+
}
|
18
|
+
|
19
|
+
function toggleCode( id ) {
|
20
|
+
if ( document.getElementById )
|
21
|
+
elem = document.getElementById( id );
|
22
|
+
else if ( document.all )
|
23
|
+
elem = eval( "document.all." + id );
|
24
|
+
else
|
25
|
+
return false;
|
26
|
+
|
27
|
+
elemStyle = elem.style;
|
28
|
+
|
29
|
+
if ( elemStyle.display != "block" ) {
|
30
|
+
elemStyle.display = "block"
|
31
|
+
} else {
|
32
|
+
elemStyle.display = "none"
|
33
|
+
}
|
34
|
+
|
35
|
+
return true;
|
36
|
+
}
|
37
|
+
|
38
|
+
// Make codeblocks hidden by default
|
39
|
+
document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
|
40
|
+
|
41
|
+
// ]]>
|
42
|
+
</script>
|
43
|
+
|
44
|
+
</head>
|
45
|
+
<body>
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
<div id="fileHeader">
|
50
|
+
<h1>LICENSE</h1>
|
51
|
+
<table class="header-table">
|
52
|
+
<tr class="top-aligned-row">
|
53
|
+
<td><strong>Path:</strong></td>
|
54
|
+
<td>LICENSE
|
55
|
+
</td>
|
56
|
+
</tr>
|
57
|
+
<tr class="top-aligned-row">
|
58
|
+
<td><strong>Last Update:</strong></td>
|
59
|
+
<td>Tue Dec 18 11:39:01 -0700 2007</td>
|
60
|
+
</tr>
|
61
|
+
</table>
|
62
|
+
</div>
|
63
|
+
<!-- banner header -->
|
64
|
+
|
65
|
+
<div id="bodyContent">
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
<div id="contextContent">
|
70
|
+
|
71
|
+
<div id="description">
|
72
|
+
<p>
|
73
|
+
Ruby is copyrighted free software by Yukihiro Matsumoto
|
74
|
+
<matz@netlab.co.jp>. You can redistribute it and/or modify it under
|
75
|
+
either the terms of the GPL (see COPYING.txt file), or the conditions
|
76
|
+
below:
|
77
|
+
</p>
|
78
|
+
<pre>
|
79
|
+
1. You may make and give away verbatim copies of the source form of the
|
80
|
+
software without restriction, provided that you duplicate all of the
|
81
|
+
original copyright notices and associated disclaimers.
|
82
|
+
|
83
|
+
2. You may modify your copy of the software in any way, provided that
|
84
|
+
you do at least ONE of the following:
|
85
|
+
|
86
|
+
a) place your modifications in the Public Domain or otherwise
|
87
|
+
make them Freely Available, such as by posting said
|
88
|
+
modifications to Usenet or an equivalent medium, or by allowing
|
89
|
+
the author to include your modifications in the software.
|
90
|
+
|
91
|
+
b) use the modified software only within your corporation or
|
92
|
+
organization.
|
93
|
+
|
94
|
+
c) rename any non-standard executables so the names do not conflict
|
95
|
+
with standard executables, which must also be provided.
|
96
|
+
|
97
|
+
d) make other distribution arrangements with the author.
|
98
|
+
|
99
|
+
3. You may distribute the software in object code or executable
|
100
|
+
form, provided that you do at least ONE of the following:
|
101
|
+
|
102
|
+
a) distribute the executables and library files of the software,
|
103
|
+
together with instructions (in the manual page or equivalent)
|
104
|
+
on where to get the original distribution.
|
105
|
+
|
106
|
+
b) accompany the distribution with the machine-readable source of
|
107
|
+
the software.
|
108
|
+
|
109
|
+
c) give non-standard executables non-standard names, with
|
110
|
+
instructions on where to get the original software distribution.
|
111
|
+
|
112
|
+
d) make other distribution arrangements with the author.
|
113
|
+
|
114
|
+
4. You may modify and include the part of the software into any other
|
115
|
+
software (possibly commercial). But some files in the distribution
|
116
|
+
are not written by the author, so that they are not under this terms.
|
117
|
+
|
118
|
+
They are gc.c(partly), utils.c(partly), regex.[ch], st.[ch] and some
|
119
|
+
files under the ./missing directory. See each file for the copying
|
120
|
+
condition.
|
121
|
+
|
122
|
+
5. The scripts and library files supplied as input to or produced as
|
123
|
+
output from the software do not automatically fall under the
|
124
|
+
copyright of the software, but belong to whomever generated them,
|
125
|
+
and may be sold commercially, and may be aggregated with this
|
126
|
+
software.
|
127
|
+
|
128
|
+
6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
|
129
|
+
IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
130
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
131
|
+
PURPOSE.
|
132
|
+
</pre>
|
133
|
+
|
134
|
+
</div>
|
135
|
+
|
136
|
+
|
137
|
+
</div>
|
138
|
+
|
139
|
+
|
140
|
+
</div>
|
141
|
+
|
142
|
+
|
143
|
+
<!-- if includes -->
|
144
|
+
|
145
|
+
<div id="section">
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
|
154
|
+
<!-- if method_list -->
|
155
|
+
|
156
|
+
|
157
|
+
</div>
|
158
|
+
|
159
|
+
|
160
|
+
<div id="validator-badges">
|
161
|
+
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
|
162
|
+
</div>
|
163
|
+
|
164
|
+
</body>
|
165
|
+
</html>
|
@@ -0,0 +1,297 @@
|
|
1
|
+
<?xml version="1.0" encoding="iso-8859-1"?>
|
2
|
+
<!DOCTYPE html
|
3
|
+
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
4
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
5
|
+
|
6
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
7
|
+
<head>
|
8
|
+
<title>File: README</title>
|
9
|
+
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
10
|
+
<meta http-equiv="Content-Script-Type" content="text/javascript" />
|
11
|
+
<link rel="stylesheet" href=".././rdoc-style.css" type="text/css" media="screen" />
|
12
|
+
<script type="text/javascript">
|
13
|
+
// <![CDATA[
|
14
|
+
|
15
|
+
function popupCode( url ) {
|
16
|
+
window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
|
17
|
+
}
|
18
|
+
|
19
|
+
function toggleCode( id ) {
|
20
|
+
if ( document.getElementById )
|
21
|
+
elem = document.getElementById( id );
|
22
|
+
else if ( document.all )
|
23
|
+
elem = eval( "document.all." + id );
|
24
|
+
else
|
25
|
+
return false;
|
26
|
+
|
27
|
+
elemStyle = elem.style;
|
28
|
+
|
29
|
+
if ( elemStyle.display != "block" ) {
|
30
|
+
elemStyle.display = "block"
|
31
|
+
} else {
|
32
|
+
elemStyle.display = "none"
|
33
|
+
}
|
34
|
+
|
35
|
+
return true;
|
36
|
+
}
|
37
|
+
|
38
|
+
// Make codeblocks hidden by default
|
39
|
+
document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
|
40
|
+
|
41
|
+
// ]]>
|
42
|
+
</script>
|
43
|
+
|
44
|
+
</head>
|
45
|
+
<body>
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
<div id="fileHeader">
|
50
|
+
<h1>README</h1>
|
51
|
+
<table class="header-table">
|
52
|
+
<tr class="top-aligned-row">
|
53
|
+
<td><strong>Path:</strong></td>
|
54
|
+
<td>README
|
55
|
+
</td>
|
56
|
+
</tr>
|
57
|
+
<tr class="top-aligned-row">
|
58
|
+
<td><strong>Last Update:</strong></td>
|
59
|
+
<td>Thu Jan 03 14:13:32 -0700 2008</td>
|
60
|
+
</tr>
|
61
|
+
</table>
|
62
|
+
</div>
|
63
|
+
<!-- banner header -->
|
64
|
+
|
65
|
+
<div id="bodyContent">
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
<div id="contextContent">
|
70
|
+
|
71
|
+
<div id="description">
|
72
|
+
<h1><a href="../classes/Rev.html">Rev</a></h1>
|
73
|
+
<p>
|
74
|
+
<a href="../classes/Rev.html">Rev</a> is a high performance event library
|
75
|
+
for Ruby 1.9. It uses the libev C library to handle support for underlying
|
76
|
+
system calls. This includes the epoll system call for Linux, the kqueue
|
77
|
+
system call for BSDs and OS X, and the completion ports interface for
|
78
|
+
Solaris.
|
79
|
+
</p>
|
80
|
+
<p>
|
81
|
+
<a href="../classes/Rev.html">Rev</a> also binds asynchronous wrappers to
|
82
|
+
Ruby‘s core socket classes so you can use them in conjunction with <a
|
83
|
+
href="../classes/Rev.html">Rev</a> to build asynchronous event-driven
|
84
|
+
applications.
|
85
|
+
</p>
|
86
|
+
<h2>Anatomy</h2>
|
87
|
+
<p>
|
88
|
+
<a href="../classes/Rev.html">Rev</a> builds on two core classes which bind
|
89
|
+
to the libev API:
|
90
|
+
</p>
|
91
|
+
<ul>
|
92
|
+
<li><a href="../classes/Rev/Loop.html">Rev::Loop</a> - This class represents an
|
93
|
+
event loop which uses underlying high performance system calls to wait for
|
94
|
+
events.
|
95
|
+
|
96
|
+
</li>
|
97
|
+
<li><a href="../classes/Rev/Watcher.html">Rev::Watcher</a> - This is the base
|
98
|
+
class for event observers. Once you attach an event observer to a loop and
|
99
|
+
start running it, you will begin receiving callbacks to particlar methods
|
100
|
+
when events occur.
|
101
|
+
|
102
|
+
</li>
|
103
|
+
</ul>
|
104
|
+
<h2>Watchers</h2>
|
105
|
+
<p>
|
106
|
+
There are presently two types of watchers:
|
107
|
+
</p>
|
108
|
+
<ul>
|
109
|
+
<li><a href="../classes/Rev/IOWatcher.html">Rev::IOWatcher</a> - This class
|
110
|
+
waits for an IO object to become readable, writable, or both.
|
111
|
+
|
112
|
+
</li>
|
113
|
+
<li><a href="../classes/Rev/TimerWatcher.html">Rev::TimerWatcher</a> - This
|
114
|
+
class waits for a specified duration then fires an event. You can also
|
115
|
+
configure it to fire an event at specified intervals.
|
116
|
+
|
117
|
+
</li>
|
118
|
+
</ul>
|
119
|
+
<h2>Using Watchers</h2>
|
120
|
+
<p>
|
121
|
+
Watchers have five important methods:
|
122
|
+
</p>
|
123
|
+
<ul>
|
124
|
+
<li>attach(loop) - This binds a watcher to the specified event loop. If the
|
125
|
+
watcher is already bound to a loop it will be detached first, then attached
|
126
|
+
to the new one.
|
127
|
+
|
128
|
+
</li>
|
129
|
+
<li>detach - This completely unbinds a watcher from an event loop.
|
130
|
+
|
131
|
+
</li>
|
132
|
+
<li>disable - This stops the watcher from receiving events but does not unbind
|
133
|
+
it from the loop. If you are trying to toggle a watcher on and off,
|
134
|
+
it‘s best to use this method (and enable) as it performs better than
|
135
|
+
completely removing the watcher from the event loop.
|
136
|
+
|
137
|
+
</li>
|
138
|
+
<li>enable - This re-enables a watcher which has been disabled in the past. The
|
139
|
+
watcher must still be bound to an event loop.
|
140
|
+
|
141
|
+
</li>
|
142
|
+
<li>evloop - This returns the <a href="../classes/Rev/Loop.html">Rev::Loop</a>
|
143
|
+
object which the watcher is currently bound to.
|
144
|
+
|
145
|
+
</li>
|
146
|
+
</ul>
|
147
|
+
<h2>Asynchronous Wrappers</h2>
|
148
|
+
<p>
|
149
|
+
Several classes which provide asynchronous event-driven wrappers for
|
150
|
+
Ruby‘s core socket classes are also provided. Among these are:
|
151
|
+
</p>
|
152
|
+
<ul>
|
153
|
+
<li><a href="../classes/Rev/TCPSocket.html">Rev::TCPSocket</a> - A buffered
|
154
|
+
wrapper to core Ruby‘s Socket class for use with TCP sockets. You can
|
155
|
+
asynchronously create outgoing TCP connections using its
|
156
|
+
Rev::TCPSocket.connect method. <a
|
157
|
+
href="../classes/Rev/TCPSocket.html">Rev::TCPSocket</a> provides write
|
158
|
+
buffering to ensure that writing never blocks, and has asynchronous
|
159
|
+
callbacks for several events, including when the connection is opened (or
|
160
|
+
failed), when data is received, when the write buffer has been written out
|
161
|
+
completely, and when the connection closes.
|
162
|
+
|
163
|
+
</li>
|
164
|
+
<li><a href="../classes/Rev/TCPServer.html">Rev::TCPServer</a> - A wrapper for
|
165
|
+
TCPServer which creates new instances of <a
|
166
|
+
href="../classes/Rev/TCPSocket.html">Rev::TCPSocket</a> (or any subclass
|
167
|
+
you wish to provide) whenever an incoming connection is received.
|
168
|
+
|
169
|
+
</li>
|
170
|
+
<li><a href="../classes/Rev/HttpClient.html">Rev::HttpClient</a> - An HTTP/1.1
|
171
|
+
client with support for chunked encoding and streaming response processing
|
172
|
+
through asynchronous callbacks.
|
173
|
+
|
174
|
+
</li>
|
175
|
+
</ul>
|
176
|
+
<h2>Example Program</h2>
|
177
|
+
<p>
|
178
|
+
Below is an example of how to write an echo server:
|
179
|
+
</p>
|
180
|
+
<pre>
|
181
|
+
HOST = 'localhost'
|
182
|
+
PORT = 4321
|
183
|
+
|
184
|
+
class EchoServerConnection < Rev::TCPSocket
|
185
|
+
def on_connect
|
186
|
+
puts "#{remote_addr}:#{remote_port} connected"
|
187
|
+
end
|
188
|
+
|
189
|
+
def on_close
|
190
|
+
puts "#{remote_addr}:#{remote_port} disconnected"
|
191
|
+
end
|
192
|
+
|
193
|
+
def on_read(data)
|
194
|
+
write data
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
server = Rev::TCPServer.new('localhost', PORT, EchoServerConnection)
|
199
|
+
server.attach(Rev::Loop.default)
|
200
|
+
|
201
|
+
puts "Echo server listening on #{HOST}:#{PORT}"
|
202
|
+
Rev::Loop.default.run
|
203
|
+
</pre>
|
204
|
+
<p>
|
205
|
+
Here a new observer type (EchoServerConnection) is made by subclassing an
|
206
|
+
existing one and adding new implementations to existing event handlers.
|
207
|
+
</p>
|
208
|
+
<p>
|
209
|
+
A new event loop is created, and a new <a
|
210
|
+
href="../classes/Rev/TCPServer.html">Rev::TCPServer</a> (whose base class
|
211
|
+
is <a href="../classes/Rev/Watcher.html">Rev::Watcher</a>) is created and
|
212
|
+
attached to the event loop.
|
213
|
+
</p>
|
214
|
+
<p>
|
215
|
+
Once this is done, the event loop is started with event_loop.run. This
|
216
|
+
method will block until there are no active watchers for the loop or the
|
217
|
+
loop is stopped explicitly with event_loop.stop.
|
218
|
+
</p>
|
219
|
+
<h2>Defining Callbacks at Runtime</h2>
|
220
|
+
<p>
|
221
|
+
It‘s often tedious to subclass in order to just change one callback.
|
222
|
+
<a href="../classes/Rev.html">Rev</a> gives you the ability to change event
|
223
|
+
callbacks on the fly (provided you haven‘t overridden them in a
|
224
|
+
subclass). This is especially useful for small one off programs or just
|
225
|
+
experimenting with the API.
|
226
|
+
</p>
|
227
|
+
<p>
|
228
|
+
Any callback (methods prefixed with on_*) can be set on the fly by passing
|
229
|
+
it a block.
|
230
|
+
</p>
|
231
|
+
<p>
|
232
|
+
Below is an example of using this syntax. It implements an echo server
|
233
|
+
identical to the one above:
|
234
|
+
</p>
|
235
|
+
<pre>
|
236
|
+
HOST = '127.0.0.1'
|
237
|
+
PORT = 4321
|
238
|
+
|
239
|
+
server = Rev::TCPServer.new(ADDR, PORT) do |c|
|
240
|
+
c.on_connect { puts "#{remote_addr}:#{remote_port} connected" }
|
241
|
+
c.on_close { puts "#{remote_addr}:#{remote_port} disconnected" }
|
242
|
+
c.on_read { |data| write data }
|
243
|
+
end
|
244
|
+
|
245
|
+
server.attach(Rev::Loop.default)
|
246
|
+
|
247
|
+
puts "Echo server listening on #{HOST}:#{PORT}"
|
248
|
+
Rev::Loop.default.run
|
249
|
+
</pre>
|
250
|
+
<p>
|
251
|
+
As you can see, it provides a more concise (albeint slightly slower)
|
252
|
+
expression of the same server as above, without the need to subclass.
|
253
|
+
</p>
|
254
|
+
<p>
|
255
|
+
<a href="../classes/Rev/TCPServer.html">Rev::TCPServer</a> will
|
256
|
+
automatically yield new connections if a block is given. In this case the
|
257
|
+
"c" variable being passed to the block is a new instance of <a
|
258
|
+
href="../classes/Rev/TCPSocket.html">Rev::TCPSocket</a> representing the
|
259
|
+
newly created connection.
|
260
|
+
</p>
|
261
|
+
<p>
|
262
|
+
The above example sets the on_connect, on_close, and on_read callbacks each
|
263
|
+
time a new connection is created.
|
264
|
+
</p>
|
265
|
+
|
266
|
+
</div>
|
267
|
+
|
268
|
+
|
269
|
+
</div>
|
270
|
+
|
271
|
+
|
272
|
+
</div>
|
273
|
+
|
274
|
+
|
275
|
+
<!-- if includes -->
|
276
|
+
|
277
|
+
<div id="section">
|
278
|
+
|
279
|
+
|
280
|
+
|
281
|
+
|
282
|
+
|
283
|
+
|
284
|
+
|
285
|
+
|
286
|
+
<!-- if method_list -->
|
287
|
+
|
288
|
+
|
289
|
+
</div>
|
290
|
+
|
291
|
+
|
292
|
+
<div id="validator-badges">
|
293
|
+
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
|
294
|
+
</div>
|
295
|
+
|
296
|
+
</body>
|
297
|
+
</html>
|