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.
Files changed (174) hide show
  1. data/.gitignore +7 -0
  2. data/.yardopts +7 -0
  3. data/Gemfile +3 -0
  4. data/README.md +109 -0
  5. data/Rakefile +14 -368
  6. data/docs/DocumentationGuidesIndex.md +27 -0
  7. data/docs/GettingStarted.md +521 -0
  8. data/docs/old/DEFERRABLES +246 -0
  9. data/docs/{KEYBOARD → old/KEYBOARD} +15 -11
  10. data/docs/old/LIGHTWEIGHT_CONCURRENCY +130 -0
  11. data/docs/old/SMTP +4 -0
  12. data/docs/old/SPAWNED_PROCESSES +148 -0
  13. data/eventmachine.gemspec +20 -26
  14. data/examples/guides/getting_started/01_eventmachine_echo_server.rb +18 -0
  15. data/examples/guides/getting_started/02_eventmachine_echo_server_that_recognizes_exit_command.rb +22 -0
  16. data/examples/guides/getting_started/03_simple_chat_server.rb +149 -0
  17. data/examples/guides/getting_started/04_simple_chat_server_step_one.rb +27 -0
  18. data/examples/guides/getting_started/05_simple_chat_server_step_two.rb +43 -0
  19. data/examples/guides/getting_started/06_simple_chat_server_step_three.rb +98 -0
  20. data/examples/guides/getting_started/07_simple_chat_server_step_four.rb +121 -0
  21. data/examples/guides/getting_started/08_simple_chat_server_step_five.rb +141 -0
  22. data/examples/{ex_channel.rb → old/ex_channel.rb} +3 -3
  23. data/examples/old/ex_tick_loop_array.rb +15 -0
  24. data/examples/old/ex_tick_loop_counter.rb +32 -0
  25. data/ext/binder.cpp +0 -1
  26. data/ext/cmain.cpp +40 -29
  27. data/ext/ed.cpp +189 -134
  28. data/ext/ed.h +34 -40
  29. data/ext/em.cpp +388 -340
  30. data/ext/em.h +29 -32
  31. data/ext/eventmachine.h +7 -6
  32. data/ext/extconf.rb +57 -48
  33. data/ext/fastfilereader/extconf.rb +5 -3
  34. data/ext/fastfilereader/mapper.cpp +1 -1
  35. data/ext/fastfilereader/rubymain.cpp +0 -1
  36. data/ext/kb.cpp +1 -3
  37. data/ext/pipe.cpp +9 -11
  38. data/ext/project.h +12 -8
  39. data/ext/rubymain.cpp +158 -112
  40. data/java/src/com/rubyeventmachine/EmReactor.java +3 -2
  41. data/lib/em/buftok.rb +35 -63
  42. data/lib/em/callback.rb +43 -11
  43. data/lib/em/channel.rb +22 -15
  44. data/lib/em/completion.rb +303 -0
  45. data/lib/em/connection.rb +341 -208
  46. data/lib/em/deferrable/pool.rb +2 -0
  47. data/lib/em/deferrable.rb +20 -2
  48. data/lib/em/file_watch.rb +37 -18
  49. data/lib/em/iterator.rb +270 -0
  50. data/lib/em/pool.rb +146 -0
  51. data/lib/em/process_watch.rb +5 -4
  52. data/lib/em/processes.rb +8 -4
  53. data/lib/em/protocols/httpclient.rb +27 -11
  54. data/lib/em/protocols/httpclient2.rb +15 -5
  55. data/lib/em/protocols/line_protocol.rb +29 -0
  56. data/lib/em/protocols/memcache.rb +17 -9
  57. data/lib/em/protocols/object_protocol.rb +2 -1
  58. data/lib/em/protocols/postgres3.rb +2 -1
  59. data/lib/em/protocols/smtpclient.rb +19 -11
  60. data/lib/em/protocols/smtpserver.rb +101 -8
  61. data/lib/em/protocols/stomp.rb +9 -7
  62. data/lib/em/protocols/tcptest.rb +3 -2
  63. data/lib/em/protocols.rb +1 -1
  64. data/lib/{pr_eventmachine.rb → em/pure_ruby.rb} +188 -205
  65. data/lib/em/queue.rb +23 -13
  66. data/lib/em/resolver.rb +192 -0
  67. data/lib/em/spawnable.rb +9 -10
  68. data/lib/em/streamer.rb +34 -46
  69. data/lib/em/threaded_resource.rb +90 -0
  70. data/lib/em/tick_loop.rb +85 -0
  71. data/lib/em/timers.rb +8 -3
  72. data/lib/em/version.rb +1 -1
  73. data/lib/eventmachine.rb +582 -686
  74. data/lib/jeventmachine.rb +25 -3
  75. data/tasks/package.rake +98 -0
  76. data/tasks/test.rake +8 -0
  77. data/tests/em_test_helper.rb +64 -0
  78. data/tests/test_attach.rb +56 -56
  79. data/tests/test_basic.rb +111 -168
  80. data/tests/test_channel.rb +5 -6
  81. data/tests/test_completion.rb +177 -0
  82. data/tests/test_connection_count.rb +1 -3
  83. data/tests/test_defer.rb +3 -32
  84. data/tests/test_deferrable.rb +35 -0
  85. data/tests/test_epoll.rb +27 -57
  86. data/tests/test_error_handler.rb +10 -7
  87. data/tests/test_exc.rb +6 -33
  88. data/tests/test_file_watch.rb +51 -35
  89. data/tests/test_futures.rb +10 -38
  90. data/tests/test_get_sock_opt.rb +27 -20
  91. data/tests/test_handler_check.rb +1 -3
  92. data/tests/test_hc.rb +49 -112
  93. data/tests/test_httpclient.rb +34 -62
  94. data/tests/test_httpclient2.rb +14 -39
  95. data/tests/test_inactivity_timeout.rb +44 -40
  96. data/tests/test_kb.rb +26 -52
  97. data/tests/test_ltp.rb +27 -71
  98. data/tests/test_ltp2.rb +1 -30
  99. data/tests/test_next_tick.rb +2 -31
  100. data/tests/test_object_protocol.rb +8 -9
  101. data/tests/test_pause.rb +45 -37
  102. data/tests/test_pending_connect_timeout.rb +42 -38
  103. data/tests/test_pool.rb +128 -0
  104. data/tests/test_process_watch.rb +37 -37
  105. data/tests/test_processes.rb +92 -110
  106. data/tests/test_proxy_connection.rb +137 -61
  107. data/tests/test_pure.rb +30 -67
  108. data/tests/test_queue.rb +10 -4
  109. data/tests/test_resolver.rb +55 -0
  110. data/tests/test_running.rb +1 -29
  111. data/tests/test_sasl.rb +8 -33
  112. data/tests/test_send_file.rb +163 -188
  113. data/tests/test_servers.rb +12 -55
  114. data/tests/test_shutdown_hooks.rb +23 -0
  115. data/tests/test_smtpclient.rb +1 -29
  116. data/tests/test_smtpserver.rb +1 -29
  117. data/tests/test_spawn.rb +2 -31
  118. data/tests/test_ssl_args.rb +9 -10
  119. data/tests/test_ssl_methods.rb +1 -3
  120. data/tests/test_ssl_verify.rb +63 -63
  121. data/tests/test_threaded_resource.rb +53 -0
  122. data/tests/test_tick_loop.rb +59 -0
  123. data/tests/test_timers.rb +52 -91
  124. data/tests/test_ud.rb +1 -29
  125. data/tests/test_unbind_reason.rb +31 -0
  126. metadata +113 -70
  127. data/README +0 -82
  128. data/docs/DEFERRABLES +0 -133
  129. data/docs/LIGHTWEIGHT_CONCURRENCY +0 -70
  130. data/docs/SMTP +0 -2
  131. data/docs/SPAWNED_PROCESSES +0 -89
  132. data/ext/cplusplus.cpp +0 -202
  133. data/ext/emwin.cpp +0 -300
  134. data/ext/emwin.h +0 -94
  135. data/ext/epoll.cpp +0 -26
  136. data/ext/epoll.h +0 -25
  137. data/ext/eventmachine_cpp.h +0 -96
  138. data/ext/files.cpp +0 -94
  139. data/ext/files.h +0 -65
  140. data/ext/sigs.cpp +0 -89
  141. data/ext/sigs.h +0 -32
  142. data/java/src/com/rubyeventmachine/application/Application.java +0 -194
  143. data/java/src/com/rubyeventmachine/application/Connection.java +0 -74
  144. data/java/src/com/rubyeventmachine/application/ConnectionFactory.java +0 -37
  145. data/java/src/com/rubyeventmachine/application/DefaultConnectionFactory.java +0 -46
  146. data/java/src/com/rubyeventmachine/application/PeriodicTimer.java +0 -38
  147. data/java/src/com/rubyeventmachine/application/Timer.java +0 -54
  148. data/java/src/com/rubyeventmachine/tests/ApplicationTest.java +0 -109
  149. data/java/src/com/rubyeventmachine/tests/ConnectTest.java +0 -148
  150. data/java/src/com/rubyeventmachine/tests/EMTest.java +0 -80
  151. data/java/src/com/rubyeventmachine/tests/TestDatagrams.java +0 -53
  152. data/java/src/com/rubyeventmachine/tests/TestServers.java +0 -75
  153. data/java/src/com/rubyeventmachine/tests/TestTimers.java +0 -90
  154. data/lib/evma/callback.rb +0 -32
  155. data/lib/evma/container.rb +0 -75
  156. data/lib/evma/factory.rb +0 -77
  157. data/lib/evma/protocol.rb +0 -87
  158. data/lib/evma/reactor.rb +0 -48
  159. data/lib/evma.rb +0 -32
  160. data/setup.rb +0 -1585
  161. data/tests/test_errors.rb +0 -82
  162. data/tests/testem.rb +0 -31
  163. data/web/whatis +0 -7
  164. /data/{docs/GNU → GNU} +0 -0
  165. /data/{docs/COPYING → LICENSE} +0 -0
  166. /data/docs/{ChangeLog → old/ChangeLog} +0 -0
  167. /data/docs/{EPOLL → old/EPOLL} +0 -0
  168. /data/docs/{INSTALL → old/INSTALL} +0 -0
  169. /data/docs/{LEGAL → old/LEGAL} +0 -0
  170. /data/docs/{PURE_RUBY → old/PURE_RUBY} +0 -0
  171. /data/docs/{RELEASE_NOTES → old/RELEASE_NOTES} +0 -0
  172. /data/docs/{TODO → old/TODO} +0 -0
  173. /data/examples/{ex_queue.rb → old/ex_queue.rb} +0 -0
  174. /data/examples/{helper.rb → old/helper.rb} +0 -0
data/tests/test_pure.rb CHANGED
@@ -1,76 +1,36 @@
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
-
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
- Host,Port = "0.0.0.0", 9060
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
- EM.run {
92
- EM.connect "0.0.0.0", 60001, TestConnrefused
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
- timeout = false
108
- EM.run {
109
- EM.start_server "0.0.0.0", 60002
110
- EM.connect "0.0.0.0", 60002, TestConnaccepted
111
- EM::Timer.new(1) {timeout = true; EM.stop}
112
- }
113
- assert_equal( false, timeout )
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
- $:.unshift "../lib"
2
- require 'eventmachine'
3
- require 'test/unit'
1
+ require 'em_test_helper'
4
2
 
5
- class TestEventMachineQueue < Test::Unit::TestCase
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
@@ -1,32 +1,4 @@
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
-
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
- # $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
-
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( Host, Port, SaslServer )
30
+ EM.start_server( "127.0.0.1", @port, SaslServer )
56
31
 
57
- c = EM.connect( Host, Port, SaslClient )
32
+ c = EM.connect( "127.0.0.1", @port, SaslClient )
58
33
  d = c.validate?( TestUser, TestPsw )
59
- d.timeout 2
34
+ d.timeout 1
60
35
  d.callback {
61
36
  resp = true
62
37
  EM.stop