eventmachine 0.12.6-x86-mswin32-60 → 0.12.8-x86-mswin32-60
Sign up to get free protection for your applications and to get access to all the features.
- data/{docs/README → README} +21 -13
- data/Rakefile +14 -4
- data/docs/DEFERRABLES +0 -5
- data/docs/INSTALL +2 -4
- data/docs/LEGAL +1 -1
- data/docs/LIGHTWEIGHT_CONCURRENCY +0 -2
- data/docs/PURE_RUBY +0 -2
- data/docs/RELEASE_NOTES +0 -2
- data/docs/SMTP +0 -7
- data/docs/SPAWNED_PROCESSES +0 -4
- data/docs/TODO +0 -2
- data/eventmachine.gemspec +41 -32
- data/examples/ex_channel.rb +43 -0
- data/examples/ex_queue.rb +2 -0
- data/examples/helper.rb +2 -0
- data/ext/cmain.cpp +685 -586
- data/ext/cplusplus.cpp +15 -6
- data/ext/ed.cpp +1732 -1522
- data/ext/ed.h +407 -380
- data/ext/em.cpp +2263 -1937
- data/ext/em.h +223 -186
- data/ext/eventmachine.h +111 -98
- data/ext/eventmachine_cpp.h +1 -0
- data/ext/extconf.rb +4 -0
- data/ext/kb.cpp +81 -82
- data/ext/pipe.cpp +349 -351
- data/ext/project.h +21 -0
- data/ext/rubymain.cpp +1047 -847
- data/ext/ssl.cpp +38 -1
- data/ext/ssl.h +5 -1
- data/java/src/com/rubyeventmachine/Application.java +7 -3
- data/java/src/com/rubyeventmachine/EmReactor.java +16 -1
- data/java/src/com/rubyeventmachine/tests/ConnectTest.java +25 -3
- data/lib/{protocols → em}/buftok.rb +16 -5
- data/lib/em/callback.rb +26 -0
- data/lib/em/channel.rb +57 -0
- data/lib/em/connection.rb +505 -0
- data/lib/em/deferrable.rb +144 -165
- data/lib/em/file_watch.rb +54 -0
- data/lib/em/future.rb +24 -25
- data/lib/em/messages.rb +1 -1
- data/lib/em/process_watch.rb +44 -0
- data/lib/em/processes.rb +119 -113
- data/lib/em/protocols.rb +35 -0
- data/lib/em/protocols/header_and_content.rb +138 -0
- data/lib/em/protocols/httpclient.rb +263 -0
- data/lib/em/protocols/httpclient2.rb +582 -0
- data/lib/{protocols → em/protocols}/line_and_text.rb +2 -2
- data/lib/em/protocols/linetext2.rb +160 -0
- data/lib/{protocols → em/protocols}/memcache.rb +37 -7
- data/lib/em/protocols/object_protocol.rb +39 -0
- data/lib/em/protocols/postgres3.rb +247 -0
- data/lib/em/protocols/saslauth.rb +175 -0
- data/lib/em/protocols/smtpclient.rb +331 -0
- data/lib/em/protocols/smtpserver.rb +547 -0
- data/lib/em/protocols/stomp.rb +200 -0
- data/lib/{protocols → em/protocols}/tcptest.rb +21 -25
- data/lib/em/queue.rb +61 -0
- data/lib/em/spawnable.rb +53 -56
- data/lib/em/streamer.rb +92 -74
- data/lib/em/timers.rb +55 -0
- data/lib/em/version.rb +3 -0
- data/lib/eventmachine.rb +1636 -1926
- data/lib/evma.rb +1 -1
- data/lib/jeventmachine.rb +106 -101
- data/lib/pr_eventmachine.rb +47 -36
- data/tasks/project.rake +2 -1
- data/tests/client.crt +31 -0
- data/tests/client.key +51 -0
- data/tests/test_attach.rb +18 -0
- data/tests/test_basic.rb +285 -231
- data/tests/test_channel.rb +63 -0
- data/tests/test_connection_count.rb +2 -2
- data/tests/test_epoll.rb +162 -163
- data/tests/test_errors.rb +36 -36
- data/tests/test_exc.rb +22 -25
- data/tests/test_file_watch.rb +49 -0
- data/tests/test_futures.rb +77 -93
- data/tests/test_hc.rb +2 -2
- data/tests/test_httpclient.rb +55 -52
- data/tests/test_httpclient2.rb +153 -155
- data/tests/test_inactivity_timeout.rb +30 -0
- data/tests/test_kb.rb +8 -9
- data/tests/test_ltp2.rb +274 -277
- data/tests/test_next_tick.rb +135 -109
- data/tests/test_object_protocol.rb +37 -0
- data/tests/test_process_watch.rb +48 -0
- data/tests/test_processes.rb +128 -95
- data/tests/test_proxy_connection.rb +92 -0
- data/tests/test_pure.rb +1 -5
- data/tests/test_queue.rb +44 -0
- data/tests/test_running.rb +9 -14
- data/tests/test_sasl.rb +32 -34
- data/tests/test_send_file.rb +175 -176
- data/tests/test_servers.rb +37 -41
- data/tests/test_smtpserver.rb +47 -55
- data/tests/test_spawn.rb +284 -291
- data/tests/test_ssl_args.rb +1 -1
- data/tests/test_ssl_methods.rb +1 -1
- data/tests/test_ssl_verify.rb +82 -0
- data/tests/test_timers.rb +81 -88
- data/tests/test_ud.rb +0 -7
- data/tests/testem.rb +1 -1
- metadata +52 -36
- data/lib/em/eventable.rb +0 -39
- data/lib/eventmachine_version.rb +0 -31
- data/lib/protocols/header_and_content.rb +0 -129
- data/lib/protocols/httpcli2.rb +0 -803
- data/lib/protocols/httpclient.rb +0 -270
- data/lib/protocols/linetext2.rb +0 -161
- data/lib/protocols/postgres.rb +0 -261
- data/lib/protocols/saslauth.rb +0 -179
- data/lib/protocols/smtpclient.rb +0 -308
- data/lib/protocols/smtpserver.rb +0 -556
- data/lib/protocols/stomp.rb +0 -153
- data/tests/test_eventables.rb +0 -77
@@ -0,0 +1,63 @@
|
|
1
|
+
$:.unshift "../lib"
|
2
|
+
require 'eventmachine'
|
3
|
+
require 'test/unit'
|
4
|
+
|
5
|
+
class TestEventMachineChannel < Test::Unit::TestCase
|
6
|
+
def test_channel_subscribe
|
7
|
+
s = 0
|
8
|
+
EM.run do
|
9
|
+
c = EM::Channel.new
|
10
|
+
c.subscribe { |v| s = v; EM.stop }
|
11
|
+
c << 1
|
12
|
+
end
|
13
|
+
assert_equal 1, s
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_channel_unsubscribe
|
17
|
+
s = 0
|
18
|
+
EM.run do
|
19
|
+
c = EM::Channel.new
|
20
|
+
subscription = c.subscribe { |v| s = v }
|
21
|
+
c.unsubscribe(subscription)
|
22
|
+
c << 1
|
23
|
+
EM.next_tick { EM.stop }
|
24
|
+
end
|
25
|
+
assert_not_equal 1, s
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_channel_pop
|
29
|
+
s = 0
|
30
|
+
EM.run do
|
31
|
+
c = EM::Channel.new
|
32
|
+
c.pop{ |v| s = v }
|
33
|
+
c << 1
|
34
|
+
c << 2
|
35
|
+
EM.next_tick { EM.stop }
|
36
|
+
end
|
37
|
+
assert_equal 1, s
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_channel_reactor_thread_push
|
41
|
+
out = []
|
42
|
+
c = EM::Channel.new
|
43
|
+
c.subscribe { |v| out << v }
|
44
|
+
Thread.new { c.push(1,2,3) }.join
|
45
|
+
assert out.empty?
|
46
|
+
|
47
|
+
EM.run { EM.next_tick { EM.stop } }
|
48
|
+
|
49
|
+
assert_equal [1,2,3], out
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_channel_reactor_thread_callback
|
53
|
+
out = []
|
54
|
+
c = EM::Channel.new
|
55
|
+
Thread.new { c.subscribe { |v| out << v } }.join
|
56
|
+
c.push(1,2,3)
|
57
|
+
assert out.empty?
|
58
|
+
|
59
|
+
EM.run { EM.next_tick { EM.stop } }
|
60
|
+
|
61
|
+
assert_equal [1,2,3], out
|
62
|
+
end
|
63
|
+
end
|
@@ -29,10 +29,10 @@ class TestConnectionCount < Test::Unit::TestCase
|
|
29
29
|
|
30
30
|
def test_with_some_connections
|
31
31
|
EM.run {
|
32
|
-
EM.start_server("127.0.0.1", 9999, Server)
|
33
32
|
$initial = EM.connection_count
|
33
|
+
EM.start_server("127.0.0.1", 9999, Server)
|
34
|
+
$server_started = EM.connection_count
|
34
35
|
EM.next_tick{
|
35
|
-
$server_started = EM.connection_count
|
36
36
|
EM.connect("127.0.0.1", 9999, Client)
|
37
37
|
}
|
38
38
|
}
|
data/tests/test_epoll.rb
CHANGED
@@ -1,163 +1,162 @@
|
|
1
|
-
# $Id$
|
2
|
-
#
|
3
|
-
# Author:: Francis Cianfrocca (gmail: blackhedd)
|
4
|
-
# Homepage:: http://rubyeventmachine.com
|
5
|
-
# Date:: 8 April 2006
|
6
|
-
#
|
7
|
-
# See EventMachine and EventMachine::Connection for documentation and
|
8
|
-
# usage examples.
|
9
|
-
#
|
10
|
-
#----------------------------------------------------------------------------
|
11
|
-
#
|
12
|
-
# Copyright (C) 2006-07 by Francis Cianfrocca. All Rights Reserved.
|
13
|
-
# Gmail: blackhedd
|
14
|
-
#
|
15
|
-
# This program is free software; you can redistribute it and/or modify
|
16
|
-
# it under the terms of either: 1) the GNU General Public License
|
17
|
-
# as published by the Free Software Foundation; either version 2 of the
|
18
|
-
# License, or (at your option) any later version; or 2) Ruby's License.
|
19
|
-
#
|
20
|
-
# See the file COPYING for complete licensing information.
|
21
|
-
#
|
22
|
-
#---------------------------------------------------------------------------
|
23
|
-
#
|
24
|
-
#
|
25
|
-
#
|
26
|
-
# TODO, and I know this doesn't belong here, but if a datagram calls
|
27
|
-
# send_data outside of a receive_data, there is no return address, and
|
28
|
-
# the result is a very confusing error message.
|
29
|
-
#
|
30
|
-
|
31
|
-
require 'eventmachine'
|
32
|
-
require 'test/unit'
|
33
|
-
|
34
|
-
|
35
|
-
class TestEpoll < Test::Unit::TestCase
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
EM.
|
97
|
-
EM.
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
1
|
+
# $Id$
|
2
|
+
#
|
3
|
+
# Author:: Francis Cianfrocca (gmail: blackhedd)
|
4
|
+
# Homepage:: http://rubyeventmachine.com
|
5
|
+
# Date:: 8 April 2006
|
6
|
+
#
|
7
|
+
# See EventMachine and EventMachine::Connection for documentation and
|
8
|
+
# usage examples.
|
9
|
+
#
|
10
|
+
#----------------------------------------------------------------------------
|
11
|
+
#
|
12
|
+
# Copyright (C) 2006-07 by Francis Cianfrocca. All Rights Reserved.
|
13
|
+
# Gmail: blackhedd
|
14
|
+
#
|
15
|
+
# This program is free software; you can redistribute it and/or modify
|
16
|
+
# it under the terms of either: 1) the GNU General Public License
|
17
|
+
# as published by the Free Software Foundation; either version 2 of the
|
18
|
+
# License, or (at your option) any later version; or 2) Ruby's License.
|
19
|
+
#
|
20
|
+
# See the file COPYING for complete licensing information.
|
21
|
+
#
|
22
|
+
#---------------------------------------------------------------------------
|
23
|
+
#
|
24
|
+
#
|
25
|
+
#
|
26
|
+
# TODO, and I know this doesn't belong here, but if a datagram calls
|
27
|
+
# send_data outside of a receive_data, there is no return address, and
|
28
|
+
# the result is a very confusing error message.
|
29
|
+
#
|
30
|
+
|
31
|
+
require 'eventmachine'
|
32
|
+
require 'test/unit'
|
33
|
+
|
34
|
+
|
35
|
+
class TestEpoll < Test::Unit::TestCase
|
36
|
+
|
37
|
+
module TestEchoServer
|
38
|
+
def receive_data data
|
39
|
+
send_data data
|
40
|
+
close_connection_after_writing
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
module TestEchoClient
|
45
|
+
def connection_completed
|
46
|
+
send_data "ABCDE"
|
47
|
+
$max += 1
|
48
|
+
end
|
49
|
+
def receive_data data
|
50
|
+
raise "bad response" unless data == "ABCDE"
|
51
|
+
end
|
52
|
+
def unbind
|
53
|
+
$n -= 1
|
54
|
+
EM.stop if $n == 0
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
|
59
|
+
# We can set the rlimit/nofile of a process but we can only set it
|
60
|
+
# higher if we're running as root.
|
61
|
+
# On most systems, the default value is 1024.
|
62
|
+
# Java doesn't (currently) implement this.
|
63
|
+
def test_rlimit
|
64
|
+
unless RUBY_PLATFORM =~ /java/ or EM.set_descriptor_table_size >= 1024
|
65
|
+
a = EM.set_descriptor_table_size
|
66
|
+
assert( a <= 1024 )
|
67
|
+
a = EM.set_descriptor_table_size( 1024 )
|
68
|
+
assert( a == 1024 )
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
# Run a high-volume version of this test by kicking the number of connections
|
73
|
+
# up past 512. (Each connection uses two sockets, a client and a server.)
|
74
|
+
# (Will require running the test as root)
|
75
|
+
# This test exercises TCP clients and servers.
|
76
|
+
#
|
77
|
+
# XXX this test causes all sort of weird issues on OSX (when run as part of the suite)
|
78
|
+
def _test_descriptors
|
79
|
+
EM.epoll
|
80
|
+
s = EM.set_descriptor_table_size 60000
|
81
|
+
EM.run {
|
82
|
+
EM.start_server "127.0.0.1", 9800, TestEchoServer
|
83
|
+
$n = 0
|
84
|
+
$max = 0
|
85
|
+
100.times {
|
86
|
+
EM.connect("127.0.0.1", 9800, TestEchoClient) {$n += 1}
|
87
|
+
}
|
88
|
+
}
|
89
|
+
assert_equal(0, $n)
|
90
|
+
assert_equal(100, $max)
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_defer
|
94
|
+
n = 0
|
95
|
+
work_proc = proc {n += 1}
|
96
|
+
callback_proc = proc {EM.stop}
|
97
|
+
EM.epoll
|
98
|
+
EM.run {
|
99
|
+
EM.defer work_proc, callback_proc
|
100
|
+
}
|
101
|
+
assert_equal( 1, n )
|
102
|
+
end unless RUBY_VERSION >= '1.9.0'
|
103
|
+
|
104
|
+
|
105
|
+
module TestDatagramServer
|
106
|
+
def receive_data dgm
|
107
|
+
$in = dgm
|
108
|
+
send_data "abcdefghij"
|
109
|
+
end
|
110
|
+
end
|
111
|
+
module TestDatagramClient
|
112
|
+
def post_init
|
113
|
+
send_datagram "1234567890", "127.0.0.1", 9500
|
114
|
+
end
|
115
|
+
def receive_data dgm
|
116
|
+
$out = dgm
|
117
|
+
EM.stop
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
def test_datagrams
|
122
|
+
$in = $out = ""
|
123
|
+
EM.epoll
|
124
|
+
EM.run {
|
125
|
+
EM.open_datagram_socket "127.0.0.1", 9500, TestDatagramServer
|
126
|
+
EM.open_datagram_socket "127.0.0.1", 0, TestDatagramClient
|
127
|
+
}
|
128
|
+
assert_equal( "1234567890", $in )
|
129
|
+
assert_equal( "abcdefghij", $out )
|
130
|
+
end
|
131
|
+
|
132
|
+
# XXX this test fails randomly..
|
133
|
+
def _test_unix_domain
|
134
|
+
fn = "/tmp/xxx.chain"
|
135
|
+
EM.epoll
|
136
|
+
s = EM.set_descriptor_table_size 60000
|
137
|
+
EM.run {
|
138
|
+
# The pure-Ruby version won't let us open the socket if the node already exists.
|
139
|
+
# Not sure, that actually may be correct and the compiled version is wrong.
|
140
|
+
# Pure Ruby also oddly won't let us make that many connections. This test used
|
141
|
+
# to run 100 times. Not sure where that lower connection-limit is coming from in
|
142
|
+
# pure Ruby.
|
143
|
+
# Let's not sweat the Unix-ness of the filename, since this test can't possibly
|
144
|
+
# work on Windows anyway.
|
145
|
+
#
|
146
|
+
File.unlink(fn) if File.exist?(fn)
|
147
|
+
EM.start_unix_domain_server fn, TestEchoServer
|
148
|
+
$n = 0
|
149
|
+
$max = 0
|
150
|
+
50.times {
|
151
|
+
EM.connect_unix_domain(fn, TestEchoClient) {$n += 1}
|
152
|
+
}
|
153
|
+
EM::add_timer(1) { $stderr.puts("test_unix_domain timed out!"); EM::stop }
|
154
|
+
}
|
155
|
+
assert_equal(0, $n)
|
156
|
+
assert_equal(50, $max)
|
157
|
+
ensure
|
158
|
+
File.unlink(fn) if File.exist?(fn)
|
159
|
+
end
|
160
|
+
|
161
|
+
end
|
162
|
+
|
data/tests/test_errors.rb
CHANGED
@@ -36,47 +36,47 @@ require 'test/unit'
|
|
36
36
|
|
37
37
|
class TestErrors < Test::Unit::TestCase
|
38
38
|
|
39
|
-
|
40
|
-
|
39
|
+
Localhost = "127.0.0.1"
|
40
|
+
Localport = 9801
|
41
41
|
|
42
|
-
|
43
|
-
|
42
|
+
def setup
|
43
|
+
end
|
44
44
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
45
|
+
def obsolete_teardown
|
46
|
+
# Calling #set_runtime_error_hook with no block restores the
|
47
|
+
# default handling of runtime_errors.
|
48
|
+
#
|
49
|
+
EM.set_runtime_error_hook
|
50
|
+
end
|
51
51
|
|
52
|
-
|
53
|
-
|
52
|
+
def test_no_tests_stub
|
53
|
+
end
|
54
54
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
55
|
+
# EM has a default handler for RuntimeErrors that are emitted from
|
56
|
+
# user written code. You can override the handler if you wish, but it's
|
57
|
+
# easier to call #set_runtime_error_hook.
|
58
|
+
# Ordinarily, an error in user code invoked by the reactor aborts the
|
59
|
+
# run.
|
60
|
+
#
|
61
|
+
def obsolete_test_unhandled_error
|
62
|
+
assert_raises( RuntimeError ) {
|
63
|
+
EM.run {
|
64
|
+
EM.add_timer(0) {raise "AAA"}
|
65
|
+
}
|
66
|
+
}
|
67
67
|
|
68
|
-
|
68
|
+
end
|
69
69
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
70
|
+
def obsolete_test_handled_error
|
71
|
+
err = nil
|
72
|
+
EM.run {
|
73
|
+
EM.set_runtime_error_hook {
|
74
|
+
err = true
|
75
|
+
EM.stop
|
76
|
+
}
|
77
|
+
EM.add_timer(0) {raise "AAA"}
|
78
|
+
}
|
79
|
+
assert err
|
80
|
+
end
|
81
81
|
end
|
82
82
|
|