rev 0.2.2 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGES +11 -0
- data/README +10 -3
- data/Rakefile +2 -2
- data/examples/echo_client.rb +35 -0
- data/examples/google.rb +8 -0
- data/examples/httpclient.rb +35 -0
- data/ext/http11_client/Makefile +149 -0
- data/ext/http11_client/http11_client.bundle +0 -0
- data/ext/http11_client/http11_client.o +0 -0
- data/ext/http11_client/http11_parser.o +0 -0
- data/ext/http11_client/mkmf.log +12 -0
- data/ext/libev/Changes +114 -1
- data/ext/libev/ev.c +212 -97
- data/ext/libev/ev.h +13 -7
- data/ext/libev/ev_epoll.c +44 -11
- data/ext/libev/ev_kqueue.c +2 -2
- data/ext/libev/ev_poll.c +3 -1
- data/ext/libev/ev_port.c +4 -4
- data/ext/libev/ev_select.c +58 -19
- data/ext/libev/ev_vars.h +5 -1
- data/ext/libev/ev_win32.c +32 -3
- data/ext/libev/ev_wrap.h +4 -0
- data/ext/libev/test_libev_win32.c +123 -0
- data/ext/libev/update_ev_wrap +0 -0
- data/ext/rev/Makefile +149 -0
- data/ext/rev/ev_wrap.h +8 -0
- data/ext/rev/extconf.rb +17 -0
- data/ext/rev/libev.c +8 -0
- data/ext/rev/libev.o +0 -0
- data/ext/rev/mkmf.log +221 -0
- data/ext/rev/rev.h +8 -2
- data/ext/rev/rev_buffer.c +2 -3
- data/ext/rev/rev_buffer.o +0 -0
- data/ext/rev/rev_ext.bundle +0 -0
- data/ext/rev/rev_ext.c +4 -3
- data/ext/rev/rev_ext.o +0 -0
- data/ext/rev/rev_io_watcher.c +1 -2
- data/ext/rev/rev_io_watcher.o +0 -0
- data/ext/rev/rev_loop.c +4 -4
- data/ext/rev/rev_loop.o +0 -0
- data/ext/rev/rev_ssl.o +0 -0
- data/ext/rev/rev_timer_watcher.c +1 -2
- data/ext/rev/rev_timer_watcher.o +0 -0
- data/ext/rev/rev_utils.c +14 -0
- data/ext/rev/rev_utils.o +0 -0
- data/ext/rev/rev_watcher.c +7 -6
- data/ext/rev/rev_watcher.o +0 -0
- data/lib/http11_client.bundle +0 -0
- data/lib/rev.rb +1 -1
- data/lib/rev/dns_resolver.rb +29 -9
- data/lib/rev/io.rb +6 -4
- data/lib/rev/listener.rb +5 -1
- data/lib/rev/loop.rb +8 -4
- data/lib/rev/server.rb +3 -2
- data/lib/rev/socket.rb +14 -5
- data/lib/rev_ext.bundle +0 -0
- data/lib/revem.rb +210 -0
- data/rev.gemspec +2 -2
- metadata +29 -3
data/lib/rev_ext.bundle
ADDED
Binary file
|
data/lib/revem.rb
ADDED
@@ -0,0 +1,210 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (C)2007 Tony Arcieri, Roger Pack
|
3
|
+
# You can redistribute this under the terms of the Ruby license
|
4
|
+
# See file LICENSE for details
|
5
|
+
#++
|
6
|
+
|
7
|
+
require File.dirname(__FILE__) + '/rev'
|
8
|
+
|
9
|
+
module EventMachine
|
10
|
+
|
11
|
+
class << self
|
12
|
+
# Start the Reactor loop
|
13
|
+
def run
|
14
|
+
yield if block_given?
|
15
|
+
Rev::Loop.default.run
|
16
|
+
end
|
17
|
+
|
18
|
+
# Stop the Reactor loop
|
19
|
+
def stop_event_loop
|
20
|
+
Rev::Loop.default.stop
|
21
|
+
end
|
22
|
+
|
23
|
+
class OneShotEMTimer < Rev::TimerWatcher
|
24
|
+
def setup(proc)
|
25
|
+
@proc = proc
|
26
|
+
end
|
27
|
+
|
28
|
+
def on_timer
|
29
|
+
@proc.call
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# ltodo: use Rev's PeriodicTimer to wrap EM's two similar to it
|
34
|
+
# todo: close all connections on 'stop', I believe
|
35
|
+
|
36
|
+
def add_timer interval, proc = nil, &block
|
37
|
+
block ||= proc
|
38
|
+
t = OneShotEMTimer.new(interval, false) # non repeating
|
39
|
+
t.setup(block)
|
40
|
+
t.attach(Rev::Loop.default) # fire 'er off ltodo: do we keep track of these timers in memory?
|
41
|
+
t
|
42
|
+
end
|
43
|
+
|
44
|
+
def cancel_timer t
|
45
|
+
t.detach if t.attached? # guess there's a case where EM you can say 'cancel' but it's already fired? kind of odd but it happens
|
46
|
+
end
|
47
|
+
|
48
|
+
def set_comm_inactivity_timeout *args; end # TODO
|
49
|
+
|
50
|
+
# Make an outgoing connection
|
51
|
+
def connect(addr, port, handler = Connection, *args, &block)
|
52
|
+
block = args.pop if Proc === args[-1]
|
53
|
+
|
54
|
+
# make sure we're a 'real' class here
|
55
|
+
klass = if (handler and handler.is_a?(Class))
|
56
|
+
handler
|
57
|
+
else
|
58
|
+
Class.new( Connection ) {handler and include handler}
|
59
|
+
end
|
60
|
+
|
61
|
+
wrapped_child = CallsBackToEM.connect(addr, port, *args) # ltodo: args? what? they're used? also TODOC TODO FIX
|
62
|
+
conn = klass.new(wrapped_child) # ltodo [?] addr, port, *args)
|
63
|
+
wrapped_child.attach(Rev::Loop.default) # necessary
|
64
|
+
conn.heres_your_socket(wrapped_child)
|
65
|
+
wrapped_child.call_back_to_this(conn) # calls post_init for us
|
66
|
+
yield conn if block_given?
|
67
|
+
end
|
68
|
+
|
69
|
+
# Start a TCP server on the given address and port
|
70
|
+
def start_server(addr, port, handler = Connection, *args, &block)
|
71
|
+
|
72
|
+
# make sure we're a 'real' class here
|
73
|
+
klass = if (handler and handler.is_a?(Class))
|
74
|
+
handler
|
75
|
+
else
|
76
|
+
Class.new( Connection ) {handler and include handler}
|
77
|
+
end
|
78
|
+
server = Rev::TCPServer.new(addr, port, CallsBackToEM, *args) { |wrapped_child|
|
79
|
+
conn = klass.new(wrapped_child)
|
80
|
+
conn.heres_your_socket(wrapped_child) # ideally NOT have this :)
|
81
|
+
wrapped_child.call_back_to_this(conn)
|
82
|
+
block.call(conn) if block
|
83
|
+
}
|
84
|
+
|
85
|
+
server.attach(Rev::Loop.default)
|
86
|
+
end
|
87
|
+
|
88
|
+
def stop_server server
|
89
|
+
server.close
|
90
|
+
end
|
91
|
+
|
92
|
+
# Set the maximum number of descriptors available to this process
|
93
|
+
def set_descriptor_table_size(nfds)
|
94
|
+
Rev::Utils.maxfds = nfds
|
95
|
+
end
|
96
|
+
|
97
|
+
# Compatibility noop. Handled automatically by libev
|
98
|
+
def epoll; end
|
99
|
+
|
100
|
+
# Compatibility noop. Handled automatically by libev
|
101
|
+
def kqueue; end
|
102
|
+
end
|
103
|
+
|
104
|
+
class CallsBackToEM < Rev::TCPSocket
|
105
|
+
class ConnectTimer < Rev::TimerWatcher
|
106
|
+
attr_accessor :parent
|
107
|
+
def on_timer
|
108
|
+
@parent.connection_has_timed_out
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
112
|
+
|
113
|
+
def call_back_to_this parent
|
114
|
+
@call_back_to_this = parent
|
115
|
+
parent.post_init
|
116
|
+
end
|
117
|
+
|
118
|
+
def on_connect
|
119
|
+
# @connection_timer.detach if @connection_timer # won't need that anymore :) -- with server connecteds we don't have it, anyway
|
120
|
+
@call_back_to_this.connection_completed if @call_back_to_this # TODO should server accepted's call this? They don't currently [and can't, since on_connect gets called basically in the initializer--needs some code love for that to happen :)
|
121
|
+
end
|
122
|
+
|
123
|
+
def connection_has_timed_out
|
124
|
+
return if closed?
|
125
|
+
close unless closed? # wonder if this works when you're within a half-connected phase. I think it does. What about TCP state?
|
126
|
+
@call_back_to_this.unbind
|
127
|
+
end
|
128
|
+
|
129
|
+
def on_write_complete; close if @should_close_after_writing; end
|
130
|
+
|
131
|
+
def should_close_after_writing
|
132
|
+
@should_close_after_writing = true;
|
133
|
+
end
|
134
|
+
|
135
|
+
def on_close
|
136
|
+
@call_back_to_this.unbind # about the same ltodo check if they ARE the same here
|
137
|
+
end
|
138
|
+
|
139
|
+
def on_resolve_failed
|
140
|
+
fail
|
141
|
+
end
|
142
|
+
|
143
|
+
def on_connect_failed
|
144
|
+
fail
|
145
|
+
end
|
146
|
+
|
147
|
+
def on_read(data)
|
148
|
+
@call_back_to_this.receive_data data
|
149
|
+
end
|
150
|
+
|
151
|
+
def fail
|
152
|
+
#@connection_timer.detch if @connection_timer
|
153
|
+
@call_back_to_this.unbind
|
154
|
+
end
|
155
|
+
|
156
|
+
def self.connect *args
|
157
|
+
a = super *args
|
158
|
+
# the connect timer currently kills TCPServer classes. I'm not sure why.
|
159
|
+
#@connection_timer = ConnectTimer.new(14) # needs to be at least higher than 12 :)
|
160
|
+
#@connection_timer.parent = a
|
161
|
+
#@connection_timer.attach(Rev::Loop.default)
|
162
|
+
a
|
163
|
+
end
|
164
|
+
|
165
|
+
end
|
166
|
+
|
167
|
+
class Connection
|
168
|
+
def self.new *args
|
169
|
+
allocate#.instance_eval do
|
170
|
+
# initialize *args
|
171
|
+
#end
|
172
|
+
end
|
173
|
+
# we will need to call 'their functions' appropriately -- the commented out ones, here
|
174
|
+
#
|
175
|
+
# Callback fired when connection is created
|
176
|
+
def post_init; end # I thought we were 'overriding' EM's existing methods, here. Huh? Why do we have to define these then?
|
177
|
+
|
178
|
+
# Callback fired when connection is closed
|
179
|
+
def unbind; end
|
180
|
+
|
181
|
+
# Callback fired when data is received
|
182
|
+
# def receive_data(data); end
|
183
|
+
def heres_your_socket instantiated_rev_socket
|
184
|
+
instantiated_rev_socket.call_back_to_this self
|
185
|
+
@wrapped_rev = instantiated_rev_socket
|
186
|
+
end
|
187
|
+
|
188
|
+
# Send data to the current connection -- called by them
|
189
|
+
def send_data(data)
|
190
|
+
@wrapped_rev.write data
|
191
|
+
end
|
192
|
+
|
193
|
+
# Close the connection, optionally after writing
|
194
|
+
def close_connection(after_writing = false)
|
195
|
+
return close_connection_after_writing if after_writing
|
196
|
+
@wrapped_rev.close
|
197
|
+
end
|
198
|
+
|
199
|
+
# Close the connection after all data has been written
|
200
|
+
def close_connection_after_writing
|
201
|
+
@wrapped_rev.output_buffer_size.zero? ? @wrapped_rev.close : @wrapped_rev.should_close_after_writing
|
202
|
+
end
|
203
|
+
|
204
|
+
def get_peername
|
205
|
+
family, port, host_name, host_ip = @wrapped_rev.peeraddr
|
206
|
+
Socket.pack_sockaddr_in( port, host_ip) # pack it up :)
|
207
|
+
end
|
208
|
+
|
209
|
+
end
|
210
|
+
end
|
data/rev.gemspec
CHANGED
@@ -2,10 +2,10 @@ require 'rubygems'
|
|
2
2
|
|
3
3
|
GEMSPEC = Gem::Specification.new do |s|
|
4
4
|
s.name = "rev"
|
5
|
-
s.version = "0.2.
|
5
|
+
s.version = "0.2.3"
|
6
6
|
s.authors = "Tony Arcieri"
|
7
7
|
s.email = "tony@medioh.com"
|
8
|
-
s.date = "
|
8
|
+
s.date = "2009-02-01"
|
9
9
|
s.summary = "Rev is a Ruby binding to the libev high performance event library"
|
10
10
|
s.platform = Gem::Platform::RUBY
|
11
11
|
s.required_ruby_version = '>= 1.8.6'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rev
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tony Arcieri
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2009-02-01 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -25,6 +25,7 @@ extra_rdoc_files:
|
|
25
25
|
- README
|
26
26
|
- CHANGES
|
27
27
|
files:
|
28
|
+
- lib/http11_client.bundle
|
28
29
|
- lib/rev
|
29
30
|
- lib/rev/async_watcher.rb
|
30
31
|
- lib/rev/dns_resolver.rb
|
@@ -39,13 +40,20 @@ files:
|
|
39
40
|
- lib/rev/ssl.rb
|
40
41
|
- lib/rev/timer_watcher.rb
|
41
42
|
- lib/rev.rb
|
43
|
+
- lib/rev_ext.bundle
|
44
|
+
- lib/revem.rb
|
42
45
|
- ext/http11_client
|
43
46
|
- ext/http11_client/ext_help.h
|
44
47
|
- ext/http11_client/extconf.rb
|
48
|
+
- ext/http11_client/http11_client.bundle
|
45
49
|
- ext/http11_client/http11_client.c
|
50
|
+
- ext/http11_client/http11_client.o
|
46
51
|
- ext/http11_client/http11_parser.c
|
47
52
|
- ext/http11_client/http11_parser.h
|
53
|
+
- ext/http11_client/http11_parser.o
|
48
54
|
- ext/http11_client/http11_parser.rl
|
55
|
+
- ext/http11_client/Makefile
|
56
|
+
- ext/http11_client/mkmf.log
|
49
57
|
- ext/libev
|
50
58
|
- ext/libev/Changes
|
51
59
|
- ext/libev/ev.c
|
@@ -61,20 +69,38 @@ files:
|
|
61
69
|
- ext/libev/LICENSE
|
62
70
|
- ext/libev/README
|
63
71
|
- ext/libev/README.embed
|
72
|
+
- ext/libev/test_libev_win32.c
|
64
73
|
- ext/libev/update_ev_wrap
|
65
74
|
- ext/rev
|
75
|
+
- ext/rev/ev_wrap.h
|
66
76
|
- ext/rev/extconf.rb
|
77
|
+
- ext/rev/libev.c
|
78
|
+
- ext/rev/libev.o
|
79
|
+
- ext/rev/Makefile
|
80
|
+
- ext/rev/mkmf.log
|
67
81
|
- ext/rev/rev.h
|
68
82
|
- ext/rev/rev_buffer.c
|
83
|
+
- ext/rev/rev_buffer.o
|
84
|
+
- ext/rev/rev_ext.bundle
|
69
85
|
- ext/rev/rev_ext.c
|
86
|
+
- ext/rev/rev_ext.o
|
70
87
|
- ext/rev/rev_io_watcher.c
|
88
|
+
- ext/rev/rev_io_watcher.o
|
71
89
|
- ext/rev/rev_loop.c
|
90
|
+
- ext/rev/rev_loop.o
|
72
91
|
- ext/rev/rev_ssl.c
|
92
|
+
- ext/rev/rev_ssl.o
|
73
93
|
- ext/rev/rev_timer_watcher.c
|
94
|
+
- ext/rev/rev_timer_watcher.o
|
74
95
|
- ext/rev/rev_utils.c
|
96
|
+
- ext/rev/rev_utils.o
|
75
97
|
- ext/rev/rev_watcher.c
|
76
98
|
- ext/rev/rev_watcher.h
|
99
|
+
- ext/rev/rev_watcher.o
|
100
|
+
- examples/echo_client.rb
|
77
101
|
- examples/echo_server.rb
|
102
|
+
- examples/google.rb
|
103
|
+
- examples/httpclient.rb
|
78
104
|
- Rakefile
|
79
105
|
- rev.gemspec
|
80
106
|
- LICENSE
|
@@ -106,7 +132,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
106
132
|
requirements: []
|
107
133
|
|
108
134
|
rubyforge_project: rev
|
109
|
-
rubygems_version: 1.
|
135
|
+
rubygems_version: 1.3.1
|
110
136
|
signing_key:
|
111
137
|
specification_version: 2
|
112
138
|
summary: Rev is a Ruby binding to the libev high performance event library
|