eventmachine-maglev- 0.12.10 → 1.0.0.beta.4
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +7 -0
- data/.yardopts +7 -0
- data/Gemfile +3 -0
- data/README.md +109 -0
- data/Rakefile +14 -368
- data/docs/DocumentationGuidesIndex.md +27 -0
- data/docs/GettingStarted.md +521 -0
- data/docs/old/DEFERRABLES +246 -0
- data/docs/{KEYBOARD → old/KEYBOARD} +15 -11
- data/docs/old/LIGHTWEIGHT_CONCURRENCY +130 -0
- data/docs/old/SMTP +4 -0
- data/docs/old/SPAWNED_PROCESSES +148 -0
- data/eventmachine.gemspec +20 -26
- data/examples/guides/getting_started/01_eventmachine_echo_server.rb +18 -0
- data/examples/guides/getting_started/02_eventmachine_echo_server_that_recognizes_exit_command.rb +22 -0
- data/examples/guides/getting_started/03_simple_chat_server.rb +149 -0
- data/examples/guides/getting_started/04_simple_chat_server_step_one.rb +27 -0
- data/examples/guides/getting_started/05_simple_chat_server_step_two.rb +43 -0
- data/examples/guides/getting_started/06_simple_chat_server_step_three.rb +98 -0
- data/examples/guides/getting_started/07_simple_chat_server_step_four.rb +121 -0
- data/examples/guides/getting_started/08_simple_chat_server_step_five.rb +141 -0
- data/examples/{ex_channel.rb → old/ex_channel.rb} +3 -3
- data/examples/old/ex_tick_loop_array.rb +15 -0
- data/examples/old/ex_tick_loop_counter.rb +32 -0
- data/ext/binder.cpp +0 -1
- data/ext/cmain.cpp +40 -29
- data/ext/ed.cpp +189 -134
- data/ext/ed.h +34 -40
- data/ext/em.cpp +388 -340
- data/ext/em.h +29 -32
- data/ext/eventmachine.h +7 -6
- data/ext/extconf.rb +57 -48
- data/ext/fastfilereader/extconf.rb +5 -3
- data/ext/fastfilereader/mapper.cpp +1 -1
- data/ext/fastfilereader/rubymain.cpp +0 -1
- data/ext/kb.cpp +1 -3
- data/ext/pipe.cpp +9 -11
- data/ext/project.h +12 -8
- data/ext/rubymain.cpp +158 -112
- data/java/src/com/rubyeventmachine/EmReactor.java +3 -2
- data/lib/em/buftok.rb +35 -63
- data/lib/em/callback.rb +43 -11
- data/lib/em/channel.rb +22 -15
- data/lib/em/completion.rb +303 -0
- data/lib/em/connection.rb +341 -208
- data/lib/em/deferrable/pool.rb +2 -0
- data/lib/em/deferrable.rb +20 -2
- data/lib/em/file_watch.rb +37 -18
- data/lib/em/iterator.rb +270 -0
- data/lib/em/pool.rb +146 -0
- data/lib/em/process_watch.rb +5 -4
- data/lib/em/processes.rb +8 -4
- data/lib/em/protocols/httpclient.rb +27 -11
- data/lib/em/protocols/httpclient2.rb +15 -5
- data/lib/em/protocols/line_protocol.rb +29 -0
- data/lib/em/protocols/memcache.rb +17 -9
- data/lib/em/protocols/object_protocol.rb +2 -1
- data/lib/em/protocols/postgres3.rb +2 -1
- data/lib/em/protocols/smtpclient.rb +19 -11
- data/lib/em/protocols/smtpserver.rb +101 -8
- data/lib/em/protocols/stomp.rb +9 -7
- data/lib/em/protocols/tcptest.rb +3 -2
- data/lib/em/protocols.rb +1 -1
- data/lib/{pr_eventmachine.rb → em/pure_ruby.rb} +188 -205
- data/lib/em/queue.rb +23 -13
- data/lib/em/resolver.rb +192 -0
- data/lib/em/spawnable.rb +9 -10
- data/lib/em/streamer.rb +34 -46
- data/lib/em/threaded_resource.rb +90 -0
- data/lib/em/tick_loop.rb +85 -0
- data/lib/em/timers.rb +8 -3
- data/lib/em/version.rb +1 -1
- data/lib/eventmachine.rb +582 -686
- data/lib/jeventmachine.rb +25 -3
- data/tasks/package.rake +98 -0
- data/tasks/test.rake +8 -0
- data/tests/em_test_helper.rb +64 -0
- data/tests/test_attach.rb +56 -56
- data/tests/test_basic.rb +111 -168
- data/tests/test_channel.rb +5 -6
- data/tests/test_completion.rb +177 -0
- data/tests/test_connection_count.rb +1 -3
- data/tests/test_defer.rb +3 -32
- data/tests/test_deferrable.rb +35 -0
- data/tests/test_epoll.rb +27 -57
- data/tests/test_error_handler.rb +10 -7
- data/tests/test_exc.rb +6 -33
- data/tests/test_file_watch.rb +51 -35
- data/tests/test_futures.rb +10 -38
- data/tests/test_get_sock_opt.rb +27 -20
- data/tests/test_handler_check.rb +1 -3
- data/tests/test_hc.rb +49 -112
- data/tests/test_httpclient.rb +34 -62
- data/tests/test_httpclient2.rb +14 -39
- data/tests/test_inactivity_timeout.rb +44 -40
- data/tests/test_kb.rb +26 -52
- data/tests/test_ltp.rb +27 -71
- data/tests/test_ltp2.rb +1 -30
- data/tests/test_next_tick.rb +2 -31
- data/tests/test_object_protocol.rb +8 -9
- data/tests/test_pause.rb +45 -37
- data/tests/test_pending_connect_timeout.rb +42 -38
- data/tests/test_pool.rb +128 -0
- data/tests/test_process_watch.rb +37 -37
- data/tests/test_processes.rb +92 -110
- data/tests/test_proxy_connection.rb +137 -61
- data/tests/test_pure.rb +30 -67
- data/tests/test_queue.rb +10 -4
- data/tests/test_resolver.rb +55 -0
- data/tests/test_running.rb +1 -29
- data/tests/test_sasl.rb +8 -33
- data/tests/test_send_file.rb +163 -188
- data/tests/test_servers.rb +12 -55
- data/tests/test_shutdown_hooks.rb +23 -0
- data/tests/test_smtpclient.rb +1 -29
- data/tests/test_smtpserver.rb +1 -29
- data/tests/test_spawn.rb +2 -31
- data/tests/test_ssl_args.rb +9 -10
- data/tests/test_ssl_methods.rb +1 -3
- data/tests/test_ssl_verify.rb +63 -63
- data/tests/test_threaded_resource.rb +53 -0
- data/tests/test_tick_loop.rb +59 -0
- data/tests/test_timers.rb +52 -91
- data/tests/test_ud.rb +1 -29
- data/tests/test_unbind_reason.rb +31 -0
- metadata +113 -70
- data/README +0 -82
- data/docs/DEFERRABLES +0 -133
- data/docs/LIGHTWEIGHT_CONCURRENCY +0 -70
- data/docs/SMTP +0 -2
- data/docs/SPAWNED_PROCESSES +0 -89
- data/ext/cplusplus.cpp +0 -202
- data/ext/emwin.cpp +0 -300
- data/ext/emwin.h +0 -94
- data/ext/epoll.cpp +0 -26
- data/ext/epoll.h +0 -25
- data/ext/eventmachine_cpp.h +0 -96
- data/ext/files.cpp +0 -94
- data/ext/files.h +0 -65
- data/ext/sigs.cpp +0 -89
- data/ext/sigs.h +0 -32
- data/java/src/com/rubyeventmachine/application/Application.java +0 -194
- data/java/src/com/rubyeventmachine/application/Connection.java +0 -74
- data/java/src/com/rubyeventmachine/application/ConnectionFactory.java +0 -37
- data/java/src/com/rubyeventmachine/application/DefaultConnectionFactory.java +0 -46
- data/java/src/com/rubyeventmachine/application/PeriodicTimer.java +0 -38
- data/java/src/com/rubyeventmachine/application/Timer.java +0 -54
- data/java/src/com/rubyeventmachine/tests/ApplicationTest.java +0 -109
- data/java/src/com/rubyeventmachine/tests/ConnectTest.java +0 -148
- data/java/src/com/rubyeventmachine/tests/EMTest.java +0 -80
- data/java/src/com/rubyeventmachine/tests/TestDatagrams.java +0 -53
- data/java/src/com/rubyeventmachine/tests/TestServers.java +0 -75
- data/java/src/com/rubyeventmachine/tests/TestTimers.java +0 -90
- data/lib/evma/callback.rb +0 -32
- data/lib/evma/container.rb +0 -75
- data/lib/evma/factory.rb +0 -77
- data/lib/evma/protocol.rb +0 -87
- data/lib/evma/reactor.rb +0 -48
- data/lib/evma.rb +0 -32
- data/setup.rb +0 -1585
- data/tests/test_errors.rb +0 -82
- data/tests/testem.rb +0 -31
- data/web/whatis +0 -7
- /data/{docs/GNU → GNU} +0 -0
- /data/{docs/COPYING → LICENSE} +0 -0
- /data/docs/{ChangeLog → old/ChangeLog} +0 -0
- /data/docs/{EPOLL → old/EPOLL} +0 -0
- /data/docs/{INSTALL → old/INSTALL} +0 -0
- /data/docs/{LEGAL → old/LEGAL} +0 -0
- /data/docs/{PURE_RUBY → old/PURE_RUBY} +0 -0
- /data/docs/{RELEASE_NOTES → old/RELEASE_NOTES} +0 -0
- /data/docs/{TODO → old/TODO} +0 -0
- /data/examples/{ex_queue.rb → old/ex_queue.rb} +0 -0
- /data/examples/{helper.rb → old/helper.rb} +0 -0
data/tests/test_pure.rb
CHANGED
@@ -1,76 +1,36 @@
|
|
1
|
-
|
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
|
-
|
27
|
-
$:.unshift "../lib"
|
28
|
-
require 'eventmachine'
|
29
|
-
require 'test/unit'
|
1
|
+
require 'em_test_helper'
|
30
2
|
|
31
3
|
class TestPure < Test::Unit::TestCase
|
32
4
|
|
33
|
-
|
34
|
-
|
35
|
-
|
5
|
+
def setup
|
6
|
+
@port = next_port
|
7
|
+
end
|
36
8
|
|
37
9
|
# These tests are intended to exercise problems that come up in the
|
38
10
|
# pure-Ruby implementation. However, we DON'T constrain them such that
|
39
11
|
# they only run in pure-Ruby. These tests need to work identically in
|
40
12
|
# any implementation.
|
41
13
|
|
42
|
-
def setup
|
43
|
-
end
|
44
|
-
|
45
|
-
def teardown
|
46
|
-
end
|
47
|
-
|
48
14
|
#-------------------------------------
|
49
15
|
|
50
16
|
# The EM reactor needs to run down open connections and release other resources
|
51
17
|
# when it stops running. Make sure this happens even if user code throws a Ruby
|
52
18
|
# exception.
|
53
|
-
# One way to see this is to run identical tests that open a TCP server and throw
|
54
|
-
# an exception. (We do this twice because an exception aborts a test. We make the
|
55
|
-
# two tests identical except for the method name because we can't predict the order
|
56
|
-
# in which the test harness will run them.)
|
57
19
|
# If exception handling is incorrect, the second test will fail with a no-bind error
|
58
20
|
# because the TCP server opened in the first test will not have been closed.
|
59
|
-
#
|
60
|
-
def run_exception
|
61
|
-
EM.run {
|
62
|
-
EM.start_server Host, Port
|
63
|
-
raise "an exception"
|
64
|
-
}
|
65
|
-
end
|
66
|
-
def test_exception_1
|
67
|
-
assert_raises( RuntimeError ) { run_exception }
|
68
|
-
end
|
69
|
-
def test_exception_2
|
70
|
-
ex_class = RUBY_PLATFORM == 'java' ? NativeException : RuntimeError
|
71
|
-
assert_raises( ex_class ) { run_exception }
|
72
|
-
end
|
73
21
|
|
22
|
+
def test_exception_handling_releases_resources
|
23
|
+
exception = Class.new(StandardError)
|
24
|
+
|
25
|
+
2.times do
|
26
|
+
assert_raises(exception) do
|
27
|
+
EM.run do
|
28
|
+
EM.start_server "127.0.0.1", @port
|
29
|
+
raise exception
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
74
34
|
|
75
35
|
# Under some circumstances, the pure Ruby library would emit an Errno::ECONNREFUSED
|
76
36
|
# exception on certain kinds of TCP connect-errors.
|
@@ -87,13 +47,16 @@ class TestPure < Test::Unit::TestCase
|
|
87
47
|
raise "should never get here"
|
88
48
|
end
|
89
49
|
end
|
50
|
+
|
90
51
|
def test_connrefused
|
91
|
-
|
92
|
-
EM.
|
93
|
-
|
52
|
+
assert_nothing_raised do
|
53
|
+
EM.run {
|
54
|
+
setup_timeout(2)
|
55
|
+
EM.connect "127.0.0.1", @port, TestConnrefused
|
56
|
+
}
|
57
|
+
end
|
94
58
|
end
|
95
59
|
|
96
|
-
|
97
60
|
# Make sure connection_completed gets called as expected with TCP clients. This is the
|
98
61
|
# opposite of test_connrefused.
|
99
62
|
# If the test fails, it will hang because EM.stop never gets called.
|
@@ -104,13 +67,13 @@ class TestPure < Test::Unit::TestCase
|
|
104
67
|
end
|
105
68
|
end
|
106
69
|
def test_connaccepted
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
70
|
+
assert_nothing_raised do
|
71
|
+
EM.run {
|
72
|
+
EM.start_server "127.0.0.1", @port
|
73
|
+
EM.connect "127.0.0.1", @port, TestConnaccepted
|
74
|
+
setup_timeout(1)
|
75
|
+
}
|
76
|
+
end
|
114
77
|
end
|
115
78
|
|
116
79
|
def test_reactor_running
|
data/tests/test_queue.rb
CHANGED
@@ -1,8 +1,6 @@
|
|
1
|
-
|
2
|
-
require 'eventmachine'
|
3
|
-
require 'test/unit'
|
1
|
+
require 'em_test_helper'
|
4
2
|
|
5
|
-
class
|
3
|
+
class TestEMQueue < Test::Unit::TestCase
|
6
4
|
def test_queue_push
|
7
5
|
s = 0
|
8
6
|
EM.run do
|
@@ -41,4 +39,12 @@ class TestEventMachineQueue < Test::Unit::TestCase
|
|
41
39
|
EM.run { EM.next_tick { EM.stop } }
|
42
40
|
assert_equal 1, x
|
43
41
|
end
|
42
|
+
|
43
|
+
def test_num_waiting
|
44
|
+
q = EM::Queue.new
|
45
|
+
many = 3
|
46
|
+
many.times { q.pop {} }
|
47
|
+
EM.run { EM.next_tick { EM.stop } }
|
48
|
+
assert_equal many, q.num_waiting
|
49
|
+
end
|
44
50
|
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'em_test_helper'
|
2
|
+
|
3
|
+
class TestResolver < Test::Unit::TestCase
|
4
|
+
def test_a
|
5
|
+
EM.run {
|
6
|
+
d = EM::DNS::Resolver.resolve "google.com"
|
7
|
+
d.errback { assert false }
|
8
|
+
d.callback { |r|
|
9
|
+
assert r
|
10
|
+
EM.stop
|
11
|
+
}
|
12
|
+
}
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_bad_host
|
16
|
+
EM.run {
|
17
|
+
d = EM::DNS::Resolver.resolve "asdfasasdf"
|
18
|
+
d.callback { assert false }
|
19
|
+
d.errback { assert true; EM.stop }
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_garbage
|
24
|
+
assert_raises( ArgumentError ) {
|
25
|
+
EM.run {
|
26
|
+
EM::DNS::Resolver.resolve 123
|
27
|
+
}
|
28
|
+
}
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_a_pair
|
32
|
+
EM.run {
|
33
|
+
d = EM::DNS::Resolver.resolve "google.com"
|
34
|
+
d.errback { assert false }
|
35
|
+
d.callback { |r|
|
36
|
+
assert_equal(Array, r.class)
|
37
|
+
assert r.size > 1
|
38
|
+
EM.stop
|
39
|
+
}
|
40
|
+
}
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_localhost
|
44
|
+
EM.run {
|
45
|
+
d = EM::DNS::Resolver.resolve "localhost"
|
46
|
+
d.errback { assert false }
|
47
|
+
d.callback { |r|
|
48
|
+
assert_equal("127.0.0.1", r.first)
|
49
|
+
assert_equal(Array, r.class)
|
50
|
+
|
51
|
+
EM.stop
|
52
|
+
}
|
53
|
+
}
|
54
|
+
end
|
55
|
+
end
|
data/tests/test_running.rb
CHANGED
@@ -1,32 +1,4 @@
|
|
1
|
-
|
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
|
-
|
27
|
-
$:.unshift "../lib"
|
28
|
-
require 'eventmachine'
|
29
|
-
require 'test/unit'
|
1
|
+
require 'em_test_helper'
|
30
2
|
|
31
3
|
class TestRunning < Test::Unit::TestCase
|
32
4
|
def test_running
|
data/tests/test_sasl.rb
CHANGED
@@ -1,32 +1,4 @@
|
|
1
|
-
|
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
|
-
|
27
|
-
$:.unshift "../lib"
|
28
|
-
require 'eventmachine'
|
29
|
-
require 'test/unit'
|
1
|
+
require 'em_test_helper'
|
30
2
|
|
31
3
|
|
32
4
|
class TestSASL < Test::Unit::TestCase
|
@@ -35,7 +7,6 @@ class TestSASL < Test::Unit::TestCase
|
|
35
7
|
# we'll use TCP so this test will work on Windows. As far as the
|
36
8
|
# protocol handlers are concerned, there's no difference.
|
37
9
|
|
38
|
-
Host,Port = "127.0.0.1",9560
|
39
10
|
TestUser,TestPsw = "someone", "password"
|
40
11
|
|
41
12
|
class SaslServer < EM::Connection
|
@@ -49,14 +20,18 @@ class TestSASL < Test::Unit::TestCase
|
|
49
20
|
include EM::Protocols::SASLauthclient
|
50
21
|
end
|
51
22
|
|
23
|
+
def setup
|
24
|
+
@port = next_port
|
25
|
+
end
|
26
|
+
|
52
27
|
def test_sasl
|
53
28
|
resp = nil
|
54
29
|
EM.run {
|
55
|
-
EM.start_server(
|
30
|
+
EM.start_server( "127.0.0.1", @port, SaslServer )
|
56
31
|
|
57
|
-
c = EM.connect(
|
32
|
+
c = EM.connect( "127.0.0.1", @port, SaslClient )
|
58
33
|
d = c.validate?( TestUser, TestPsw )
|
59
|
-
d.timeout
|
34
|
+
d.timeout 1
|
60
35
|
d.callback {
|
61
36
|
resp = true
|
62
37
|
EM.stop
|