eventmachine 1.2.0.dev.2-x64-mingw32

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.
Files changed (181) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +105 -0
  3. data/GNU +281 -0
  4. data/LICENSE +60 -0
  5. data/README.md +108 -0
  6. data/docs/DocumentationGuidesIndex.md +27 -0
  7. data/docs/GettingStarted.md +521 -0
  8. data/docs/old/ChangeLog +211 -0
  9. data/docs/old/DEFERRABLES +246 -0
  10. data/docs/old/EPOLL +141 -0
  11. data/docs/old/INSTALL +13 -0
  12. data/docs/old/KEYBOARD +42 -0
  13. data/docs/old/LEGAL +25 -0
  14. data/docs/old/LIGHTWEIGHT_CONCURRENCY +130 -0
  15. data/docs/old/PURE_RUBY +75 -0
  16. data/docs/old/RELEASE_NOTES +94 -0
  17. data/docs/old/SMTP +4 -0
  18. data/docs/old/SPAWNED_PROCESSES +148 -0
  19. data/docs/old/TODO +8 -0
  20. data/examples/guides/getting_started/01_eventmachine_echo_server.rb +18 -0
  21. data/examples/guides/getting_started/02_eventmachine_echo_server_that_recognizes_exit_command.rb +22 -0
  22. data/examples/guides/getting_started/03_simple_chat_server.rb +149 -0
  23. data/examples/guides/getting_started/04_simple_chat_server_step_one.rb +27 -0
  24. data/examples/guides/getting_started/05_simple_chat_server_step_two.rb +43 -0
  25. data/examples/guides/getting_started/06_simple_chat_server_step_three.rb +98 -0
  26. data/examples/guides/getting_started/07_simple_chat_server_step_four.rb +121 -0
  27. data/examples/guides/getting_started/08_simple_chat_server_step_five.rb +141 -0
  28. data/examples/old/ex_channel.rb +43 -0
  29. data/examples/old/ex_queue.rb +2 -0
  30. data/examples/old/ex_tick_loop_array.rb +15 -0
  31. data/examples/old/ex_tick_loop_counter.rb +32 -0
  32. data/examples/old/helper.rb +2 -0
  33. data/ext/binder.cpp +124 -0
  34. data/ext/binder.h +46 -0
  35. data/ext/cmain.cpp +988 -0
  36. data/ext/ed.cpp +2111 -0
  37. data/ext/ed.h +442 -0
  38. data/ext/em.cpp +2379 -0
  39. data/ext/em.h +308 -0
  40. data/ext/eventmachine.h +143 -0
  41. data/ext/extconf.rb +270 -0
  42. data/ext/fastfilereader/extconf.rb +110 -0
  43. data/ext/fastfilereader/mapper.cpp +216 -0
  44. data/ext/fastfilereader/mapper.h +59 -0
  45. data/ext/fastfilereader/rubymain.cpp +127 -0
  46. data/ext/kb.cpp +79 -0
  47. data/ext/page.cpp +107 -0
  48. data/ext/page.h +51 -0
  49. data/ext/pipe.cpp +354 -0
  50. data/ext/project.h +176 -0
  51. data/ext/rubymain.cpp +1504 -0
  52. data/ext/ssl.cpp +615 -0
  53. data/ext/ssl.h +103 -0
  54. data/java/.classpath +8 -0
  55. data/java/.project +17 -0
  56. data/java/src/com/rubyeventmachine/EmReactor.java +591 -0
  57. data/java/src/com/rubyeventmachine/EmReactorException.java +40 -0
  58. data/java/src/com/rubyeventmachine/EventableChannel.java +72 -0
  59. data/java/src/com/rubyeventmachine/EventableDatagramChannel.java +201 -0
  60. data/java/src/com/rubyeventmachine/EventableSocketChannel.java +415 -0
  61. data/lib/2.0/fastfilereaderext.so +0 -0
  62. data/lib/2.0/rubyeventmachine.so +0 -0
  63. data/lib/2.1/fastfilereaderext.so +0 -0
  64. data/lib/2.1/rubyeventmachine.so +0 -0
  65. data/lib/2.2/fastfilereaderext.so +0 -0
  66. data/lib/2.2/rubyeventmachine.so +0 -0
  67. data/lib/2.3/fastfilereaderext.so +0 -0
  68. data/lib/2.3/rubyeventmachine.so +0 -0
  69. data/lib/em/buftok.rb +59 -0
  70. data/lib/em/callback.rb +58 -0
  71. data/lib/em/channel.rb +69 -0
  72. data/lib/em/completion.rb +304 -0
  73. data/lib/em/connection.rb +770 -0
  74. data/lib/em/deferrable.rb +210 -0
  75. data/lib/em/deferrable/pool.rb +2 -0
  76. data/lib/em/file_watch.rb +73 -0
  77. data/lib/em/future.rb +61 -0
  78. data/lib/em/iterator.rb +252 -0
  79. data/lib/em/messages.rb +66 -0
  80. data/lib/em/pool.rb +151 -0
  81. data/lib/em/process_watch.rb +45 -0
  82. data/lib/em/processes.rb +123 -0
  83. data/lib/em/protocols.rb +37 -0
  84. data/lib/em/protocols/header_and_content.rb +138 -0
  85. data/lib/em/protocols/httpclient.rb +299 -0
  86. data/lib/em/protocols/httpclient2.rb +600 -0
  87. data/lib/em/protocols/line_and_text.rb +125 -0
  88. data/lib/em/protocols/line_protocol.rb +29 -0
  89. data/lib/em/protocols/linetext2.rb +166 -0
  90. data/lib/em/protocols/memcache.rb +331 -0
  91. data/lib/em/protocols/object_protocol.rb +46 -0
  92. data/lib/em/protocols/postgres3.rb +246 -0
  93. data/lib/em/protocols/saslauth.rb +175 -0
  94. data/lib/em/protocols/smtpclient.rb +394 -0
  95. data/lib/em/protocols/smtpserver.rb +666 -0
  96. data/lib/em/protocols/socks4.rb +66 -0
  97. data/lib/em/protocols/stomp.rb +205 -0
  98. data/lib/em/protocols/tcptest.rb +54 -0
  99. data/lib/em/pure_ruby.rb +1022 -0
  100. data/lib/em/queue.rb +80 -0
  101. data/lib/em/resolver.rb +232 -0
  102. data/lib/em/spawnable.rb +84 -0
  103. data/lib/em/streamer.rb +118 -0
  104. data/lib/em/threaded_resource.rb +90 -0
  105. data/lib/em/tick_loop.rb +85 -0
  106. data/lib/em/timers.rb +61 -0
  107. data/lib/em/version.rb +3 -0
  108. data/lib/eventmachine.rb +1584 -0
  109. data/lib/fastfilereaderext.rb +2 -0
  110. data/lib/jeventmachine.rb +301 -0
  111. data/lib/rubyeventmachine.rb +2 -0
  112. data/rakelib/package.rake +120 -0
  113. data/rakelib/test.rake +8 -0
  114. data/tests/client.crt +31 -0
  115. data/tests/client.key +51 -0
  116. data/tests/dhparam.pem +13 -0
  117. data/tests/em_test_helper.rb +151 -0
  118. data/tests/test_attach.rb +151 -0
  119. data/tests/test_basic.rb +283 -0
  120. data/tests/test_channel.rb +75 -0
  121. data/tests/test_completion.rb +178 -0
  122. data/tests/test_connection_count.rb +54 -0
  123. data/tests/test_connection_write.rb +35 -0
  124. data/tests/test_defer.rb +35 -0
  125. data/tests/test_deferrable.rb +35 -0
  126. data/tests/test_epoll.rb +142 -0
  127. data/tests/test_error_handler.rb +38 -0
  128. data/tests/test_exc.rb +28 -0
  129. data/tests/test_file_watch.rb +66 -0
  130. data/tests/test_fork.rb +75 -0
  131. data/tests/test_futures.rb +170 -0
  132. data/tests/test_get_sock_opt.rb +37 -0
  133. data/tests/test_handler_check.rb +35 -0
  134. data/tests/test_hc.rb +155 -0
  135. data/tests/test_httpclient.rb +233 -0
  136. data/tests/test_httpclient2.rb +128 -0
  137. data/tests/test_idle_connection.rb +25 -0
  138. data/tests/test_inactivity_timeout.rb +54 -0
  139. data/tests/test_ipv4.rb +125 -0
  140. data/tests/test_ipv6.rb +131 -0
  141. data/tests/test_iterator.rb +115 -0
  142. data/tests/test_kb.rb +28 -0
  143. data/tests/test_line_protocol.rb +33 -0
  144. data/tests/test_ltp.rb +138 -0
  145. data/tests/test_ltp2.rb +308 -0
  146. data/tests/test_many_fds.rb +22 -0
  147. data/tests/test_next_tick.rb +104 -0
  148. data/tests/test_object_protocol.rb +36 -0
  149. data/tests/test_pause.rb +107 -0
  150. data/tests/test_pending_connect_timeout.rb +52 -0
  151. data/tests/test_pool.rb +196 -0
  152. data/tests/test_process_watch.rb +50 -0
  153. data/tests/test_processes.rb +128 -0
  154. data/tests/test_proxy_connection.rb +180 -0
  155. data/tests/test_pure.rb +88 -0
  156. data/tests/test_queue.rb +64 -0
  157. data/tests/test_resolver.rb +104 -0
  158. data/tests/test_running.rb +14 -0
  159. data/tests/test_sasl.rb +47 -0
  160. data/tests/test_send_file.rb +217 -0
  161. data/tests/test_servers.rb +33 -0
  162. data/tests/test_set_sock_opt.rb +39 -0
  163. data/tests/test_shutdown_hooks.rb +23 -0
  164. data/tests/test_smtpclient.rb +75 -0
  165. data/tests/test_smtpserver.rb +57 -0
  166. data/tests/test_spawn.rb +293 -0
  167. data/tests/test_ssl_args.rb +78 -0
  168. data/tests/test_ssl_dhparam.rb +83 -0
  169. data/tests/test_ssl_ecdh_curve.rb +79 -0
  170. data/tests/test_ssl_extensions.rb +49 -0
  171. data/tests/test_ssl_methods.rb +65 -0
  172. data/tests/test_ssl_protocols.rb +246 -0
  173. data/tests/test_ssl_verify.rb +126 -0
  174. data/tests/test_stomp.rb +37 -0
  175. data/tests/test_system.rb +46 -0
  176. data/tests/test_threaded_resource.rb +61 -0
  177. data/tests/test_tick_loop.rb +59 -0
  178. data/tests/test_timers.rb +123 -0
  179. data/tests/test_ud.rb +8 -0
  180. data/tests/test_unbind_reason.rb +52 -0
  181. metadata +381 -0
@@ -0,0 +1,126 @@
1
+ require 'em_test_helper'
2
+
3
+ class TestSslVerify < Test::Unit::TestCase
4
+ def setup
5
+ $dir = File.dirname(File.expand_path(__FILE__)) + '/'
6
+ $cert_from_file = File.read($dir+'client.crt')
7
+ end
8
+
9
+ module ClientNoCert
10
+ def connection_completed
11
+ start_tls()
12
+ end
13
+
14
+ def ssl_handshake_completed
15
+ $client_handshake_completed = true
16
+ close_connection
17
+ end
18
+
19
+ def unbind
20
+ EM.stop_event_loop
21
+ end
22
+ end
23
+
24
+ module Client
25
+ def connection_completed
26
+ start_tls(:private_key_file => $dir+'client.key', :cert_chain_file => $dir+'client.crt')
27
+ end
28
+
29
+ def ssl_handshake_completed
30
+ $client_handshake_completed = true
31
+ close_connection
32
+ end
33
+
34
+ def unbind
35
+ EM.stop_event_loop
36
+ end
37
+ end
38
+
39
+ module AcceptServer
40
+ def post_init
41
+ start_tls(:verify_peer => true)
42
+ end
43
+
44
+ def ssl_verify_peer(cert)
45
+ $cert_from_server = cert
46
+ true
47
+ end
48
+
49
+ def ssl_handshake_completed
50
+ $server_handshake_completed = true
51
+ end
52
+ end
53
+
54
+ module DenyServer
55
+ def post_init
56
+ start_tls(:verify_peer => true)
57
+ end
58
+
59
+ def ssl_verify_peer(cert)
60
+ $cert_from_server = cert
61
+ # Do not accept the peer. This should now cause the connection to shut down without the SSL handshake being completed.
62
+ false
63
+ end
64
+
65
+ def ssl_handshake_completed
66
+ $server_handshake_completed = true
67
+ end
68
+ end
69
+
70
+ module FailServerNoPeerCert
71
+ def post_init
72
+ start_tls(:verify_peer => true, :fail_if_no_peer_cert => true)
73
+ end
74
+
75
+ def ssl_verify_peer(cert)
76
+ raise "Verify peer should not get called for a client without a certificate"
77
+ end
78
+
79
+ def ssl_handshake_completed
80
+ $server_handshake_completed = true
81
+ end
82
+ end
83
+
84
+ def test_fail_no_peer_cert
85
+ omit_unless(EM.ssl?)
86
+ omit_if(rbx?)
87
+
88
+ $client_handshake_completed, $server_handshake_completed = false, false
89
+
90
+ EM.run {
91
+ EM.start_server("127.0.0.1", 16784, FailServerNoPeerCert)
92
+ EM.connect("127.0.0.1", 16784, ClientNoCert)
93
+ }
94
+
95
+ assert(!$client_handshake_completed)
96
+ assert(!$server_handshake_completed)
97
+ end
98
+
99
+ def test_accept_server
100
+ omit_unless(EM.ssl?)
101
+ omit_if(rbx?)
102
+ $client_handshake_completed, $server_handshake_completed = false, false
103
+ EM.run {
104
+ EM.start_server("127.0.0.1", 16784, AcceptServer)
105
+ EM.connect("127.0.0.1", 16784, Client).instance_variable_get("@signature")
106
+ }
107
+
108
+ assert_equal($cert_from_file, $cert_from_server)
109
+ assert($client_handshake_completed)
110
+ assert($server_handshake_completed)
111
+ end
112
+
113
+ def test_deny_server
114
+ omit_unless(EM.ssl?)
115
+ omit_if(rbx?)
116
+ $client_handshake_completed, $server_handshake_completed = false, false
117
+ EM.run {
118
+ EM.start_server("127.0.0.1", 16784, DenyServer)
119
+ EM.connect("127.0.0.1", 16784, Client)
120
+ }
121
+
122
+ assert_equal($cert_from_file, $cert_from_server)
123
+ assert(!$client_handshake_completed)
124
+ assert(!$server_handshake_completed)
125
+ end
126
+ end
@@ -0,0 +1,37 @@
1
+ require 'em_test_helper'
2
+
3
+ class TestStomp < Test::Unit::TestCase
4
+ CONTENT_LENGTH_REGEX = /^content-length: (\d+)$/
5
+
6
+ def bytesize(str)
7
+ str = str.to_s
8
+ size = str.bytesize if str.respond_to?(:bytesize) # bytesize added in 1.9
9
+ size || str.size
10
+ end
11
+
12
+ def test_content_length_in_bytes
13
+ connection = Object.new
14
+ connection.instance_eval do
15
+ extend EM::P::Stomp
16
+
17
+ def last_sent_content_length
18
+ @sent && Integer(@sent[CONTENT_LENGTH_REGEX, 1])
19
+ end
20
+
21
+ def send_data(string)
22
+ @sent = string
23
+ end
24
+ end
25
+
26
+ queue = "queue"
27
+ failure_message = "header content-length is not the byte size of last sent body"
28
+
29
+ body = "test"
30
+ connection.send queue, body
31
+ assert_equal bytesize(body), connection.last_sent_content_length, failure_message
32
+
33
+ body = "test\u221A"
34
+ connection.send queue, body
35
+ assert_equal bytesize(body), connection.last_sent_content_length, failure_message
36
+ end
37
+ end
@@ -0,0 +1,46 @@
1
+ # coding: utf-8
2
+ require 'em_test_helper'
3
+
4
+ class TestSystem < Test::Unit::TestCase
5
+ def setup
6
+ @filename = File.expand_path("../я манал dump.txt", __FILE__)
7
+ @test_data = 'a' * 100
8
+ File.open(@filename, 'w'){|f| f.write(@test_data)}
9
+ end
10
+
11
+ def test_system
12
+ omit_if(windows?)
13
+
14
+ result = nil
15
+ status = nil
16
+ EM.run {
17
+ EM.system('cat', @filename){|out, state|
18
+ result = out
19
+ status = state.exitstatus
20
+ EM.stop
21
+ }
22
+ }
23
+ assert_equal(0, status)
24
+ assert_equal(@test_data, result)
25
+ end
26
+
27
+ def test_system_with_string
28
+ omit_if(windows?)
29
+
30
+ result = nil
31
+ status = nil
32
+ EM.run {
33
+ EM.system("cat '#@filename'"){|out, state|
34
+ result = out
35
+ status = state.exitstatus
36
+ EM.stop
37
+ }
38
+ }
39
+ assert_equal(0, status)
40
+ assert_equal(@test_data, result)
41
+ end
42
+
43
+ def teardown
44
+ File.unlink(@filename)
45
+ end
46
+ end
@@ -0,0 +1,61 @@
1
+ class TestThreadedResource < Test::Unit::TestCase
2
+ def object
3
+ @object ||= {}
4
+ end
5
+
6
+ def resource
7
+ @resource = EM::ThreadedResource.new do
8
+ object
9
+ end
10
+ end
11
+
12
+ def teardown
13
+ resource.shutdown
14
+ end
15
+
16
+ def test_dispatch_completion
17
+ EM.run do
18
+ EM.add_timer(3) do
19
+ EM.stop
20
+ fail 'Resource dispatch timed out'
21
+ end
22
+ completion = resource.dispatch do |o|
23
+ o[:foo] = :bar
24
+ :foo
25
+ end
26
+ completion.callback do |result|
27
+ assert_equal :foo, result
28
+ EM.stop
29
+ end
30
+ completion.errback do |error|
31
+ EM.stop
32
+ fail "Unexpected error: #{error.message}"
33
+ end
34
+ end
35
+ assert_equal :bar, object[:foo]
36
+ end
37
+
38
+ def test_dispatch_failure
39
+ completion = resource.dispatch do |o|
40
+ raise 'boom'
41
+ end
42
+ completion.errback do |error|
43
+ assert_kind_of RuntimeError, error
44
+ assert_equal 'boom', error.message
45
+ end
46
+ end
47
+
48
+ def test_dispatch_threading
49
+ main = Thread.current
50
+ resource.dispatch do |o|
51
+ o[:dispatch_thread] = Thread.current
52
+ end
53
+ assert_not_equal main, object[:dispatch_thread]
54
+ end
55
+
56
+ def test_shutdown
57
+ # This test should get improved sometime. The method returning thread is
58
+ # NOT an api that will be maintained.
59
+ assert !resource.shutdown.alive?
60
+ end
61
+ end
@@ -0,0 +1,59 @@
1
+ require "test/unit"
2
+ require 'em_test_helper'
3
+
4
+ class TestEmTickLoop < Test::Unit::TestCase
5
+ def test_em_tick_loop
6
+ i = 0
7
+ EM.tick_loop { i += 1; EM.stop if i == 10 }
8
+ EM.run { EM.add_timer(1) { EM.stop } }
9
+ assert_equal i, 10
10
+ end
11
+
12
+ def test_tick_loop_on_stop
13
+ t = nil
14
+ tick_loop = EM.tick_loop { :stop }
15
+ tick_loop.on_stop { t = true }
16
+ EM.run { EM.next_tick { EM.stop } }
17
+ assert t
18
+ end
19
+
20
+ def test_start_twice
21
+ i = 0
22
+ s = 0
23
+ tick_loop = EM.tick_loop { i += 1; :stop }
24
+ tick_loop.on_stop { s += 1; EM.stop }
25
+ EM.run { EM.next_tick { EM.stop } }
26
+ assert_equal 1, i
27
+ assert_equal 1, s
28
+ tick_loop.start
29
+ EM.run { EM.next_tick { EM.stop } }
30
+ assert_equal 2, i
31
+ assert_equal 1, s # stop callbacks are only called once
32
+ end
33
+
34
+ def test_stop
35
+ i, s = 0, 0
36
+ tick_loop = EM.tick_loop { i += 1 }
37
+ tick_loop.on_stop { s += 1 }
38
+ EM.run { EM.next_tick { tick_loop.stop; EM.next_tick { EM.stop } } }
39
+ assert tick_loop.stopped?
40
+ assert_equal 1, i
41
+ assert_equal 1, s
42
+ end
43
+
44
+ def test_immediate_stops
45
+ s = 0
46
+ tick_loop = EM::TickLoop.new { }
47
+ tick_loop.on_stop { s += 1 }
48
+ tick_loop.on_stop { s += 1 }
49
+ assert_equal 2, s
50
+ end
51
+
52
+ def test_stopped
53
+ tick_loop = EM::TickLoop.new { }
54
+ assert tick_loop.stopped?
55
+ tick_loop.start
56
+ assert !tick_loop.stopped?
57
+ end
58
+
59
+ end
@@ -0,0 +1,123 @@
1
+ require 'em_test_helper'
2
+
3
+ class TestTimers < Test::Unit::TestCase
4
+
5
+ def test_timer_with_block
6
+ x = false
7
+ EM.run {
8
+ EM::Timer.new(0) {
9
+ x = true
10
+ EM.stop
11
+ }
12
+ }
13
+ assert x
14
+ end
15
+
16
+ def test_timer_with_proc
17
+ x = false
18
+ EM.run {
19
+ EM::Timer.new(0, proc {
20
+ x = true
21
+ EM.stop
22
+ })
23
+ }
24
+ assert x
25
+ end
26
+
27
+ def test_timer_cancel
28
+ assert_nothing_raised do
29
+ EM.run {
30
+ timer = EM::Timer.new(0.01) { flunk "Timer was not cancelled." }
31
+ timer.cancel
32
+
33
+ EM.add_timer(0.02) { EM.stop }
34
+ }
35
+ end
36
+ end
37
+
38
+ def test_periodic_timer
39
+ x = 0
40
+ EM.run {
41
+ EM::PeriodicTimer.new(0.01) do
42
+ x += 1
43
+ EM.stop if x == 4
44
+ end
45
+ }
46
+
47
+ assert_equal 4, x
48
+ end
49
+
50
+ def test_add_periodic_timer
51
+ x = 0
52
+ EM.run {
53
+ t = EM.add_periodic_timer(0.01) do
54
+ x += 1
55
+ EM.stop if x == 4
56
+ end
57
+ assert t.respond_to?(:cancel)
58
+ }
59
+ assert_equal 4, x
60
+ end
61
+
62
+ def test_periodic_timer_cancel
63
+ x = 0
64
+ EM.run {
65
+ pt = EM::PeriodicTimer.new(0.01) { x += 1 }
66
+ pt.cancel
67
+ EM::Timer.new(0.02) { EM.stop }
68
+ }
69
+ assert_equal 0, x
70
+ end
71
+
72
+ def test_add_periodic_timer_cancel
73
+ x = 0
74
+ EM.run {
75
+ pt = EM.add_periodic_timer(0.01) { x += 1 }
76
+ EM.cancel_timer(pt)
77
+ EM.add_timer(0.02) { EM.stop }
78
+ }
79
+ assert_equal 0, x
80
+ end
81
+
82
+ def test_periodic_timer_self_cancel
83
+ x = 0
84
+ EM.run {
85
+ pt = EM::PeriodicTimer.new(0) {
86
+ x += 1
87
+ if x == 4
88
+ pt.cancel
89
+ EM.stop
90
+ end
91
+ }
92
+ }
93
+ assert_equal 4, x
94
+ end
95
+
96
+
97
+ # This test is only applicable to compiled versions of the reactor.
98
+ # Pure ruby and java versions have no built-in limit on the number of outstanding timers.
99
+ unless [:pure_ruby, :java].include? EM.library_type
100
+ def test_timer_change_max_outstanding
101
+ defaults = EM.get_max_timers
102
+ EM.set_max_timers(100)
103
+
104
+ one_hundred_one_timers = lambda do
105
+ 101.times { EM.add_timer(0.01) {} }
106
+ EM.stop
107
+ end
108
+
109
+ assert_raises(RuntimeError) do
110
+ EM.run( &one_hundred_one_timers )
111
+ end
112
+
113
+ EM.set_max_timers( 101 )
114
+
115
+ assert_nothing_raised do
116
+ EM.run( &one_hundred_one_timers )
117
+ end
118
+ ensure
119
+ EM.set_max_timers(defaults)
120
+ end
121
+ end
122
+
123
+ end