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,51 @@
1
+ -----BEGIN RSA PRIVATE KEY-----
2
+ MIIJKAIBAAKCAgEAv1FSOIX1z7CQtVBFlrB0A3/V29T+22STKKmiRWYkKL5b+hkr
3
+ p9IZ5J4phZHgUVM2VDPOO2Oc2PU6dlGGZISg+UPERunTogxQKezCV0vcE9cKOwzx
4
+ CFDRvv5rK8aKMscfBLbNKocAXywuRRQmdxPiVRzbyPrl+qCr/EDLXAX3D77lS8n2
5
+ AwDg19VyI+IgFUE+Dy5e1eLoY6nV+Mq+vNXdn3ttF3t+ngac5pj5Q9h+pD5p67ba
6
+ DHSnf/7cy2fa/LKrLolVHQR9G2K6cEfeM99NtcsMbkoPs4iI3FA05OVTQHXgC8C8
7
+ cRxrb9APl95I/ep65OIaCJgcdYxJ3QD3qOtQo6/NQsGnjbyiUxaEpjfqyT1NuzWD
8
+ 81Q8uXGNS8yD6dDynt/lseBjyp2nfC3uQ5fY18VdIcu0MJ9pezBUKrNuhlsyXXEZ
9
+ 2DXj4sY8QOvIcBqSB/zmS1nGEK55xrtkaiaNrY8fe8wRVpcPLxy+P225NFw+B69F
10
+ JRA0Lj6Jt9BM4hV/3MSIEWwTVhuw4E02ywDYTzz1wq3ITf0tsbIPn0hXQMxDohhA
11
+ oKioM6u+yHtqsxD0eY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eifSXBTMJWWFVC0fkGIMb9PTZfZHyAC54lpuxzVki0HIyQG9Fs
9
+ 41zBJ5e8eEoXXlfUYtduUC35YGy2IxSzYLAJE76rctAZSWghha9xLOCDFoLjMr8h
10
+ FosKeHKJcBQ0bc8ymOpRIfrYLWhc0Pz2zkpJ/4eYw9t7NYg7S+jP19IE0gUnuM9v
11
+ SpoYMtS28tP9nEdokdwuBKD0D3bJEBBefDlHgfXoMgvy9Hivc9PBGGNTNpyFPpwF
12
+ sWVAkfhoNMJMC5V7LZsze+lftiDtzVoLSPDa9bO4BK7b/MgwCxfOhGsCAQI=
13
+ -----END DH PARAMETERS-----
@@ -0,0 +1,151 @@
1
+ require 'eventmachine'
2
+ require 'test/unit'
3
+ require 'rbconfig'
4
+ require 'socket'
5
+
6
+ class Test::Unit::TestCase
7
+ class EMTestTimeout < StandardError ; end
8
+
9
+ def setup_timeout(timeout = TIMEOUT_INTERVAL)
10
+ EM.schedule {
11
+ EM.add_timer(timeout) {
12
+ raise EMTestTimeout, "Test was cancelled after #{timeout} seconds."
13
+ }
14
+ }
15
+ end
16
+
17
+ def port_in_use?(port, host="127.0.0.1")
18
+ s = TCPSocket.new(host, port)
19
+ s.close
20
+ s
21
+ rescue Errno::ECONNREFUSED
22
+ false
23
+ end
24
+
25
+ def next_port
26
+ @@port ||= 9000
27
+ begin
28
+ @@port += 1
29
+ end while port_in_use?(@@port)
30
+
31
+ @@port
32
+ end
33
+
34
+ # Returns true if the host have a localhost 127.0.0.1 IPv4.
35
+ def self.local_ipv4?
36
+ return @@has_local_ipv4 if defined?(@@has_local_ipv4)
37
+ begin
38
+ get_my_ipv4_address "127.0.0.1"
39
+ @@has_local_ipv4 = true
40
+ rescue
41
+ @@has_local_ipv4 = false
42
+ end
43
+ end
44
+
45
+ # Returns true if the host have a public IPv4 and stores it in
46
+ # @@public_ipv4.
47
+ def self.public_ipv4?
48
+ return @@has_public_ipv4 if defined?(@@has_public_ipv4)
49
+ begin
50
+ @@public_ipv4 = get_my_ipv4_address "1.2.3.4"
51
+ @@has_public_ipv4 = true
52
+ rescue
53
+ @@has_public_ipv4 = false
54
+ end
55
+ end
56
+
57
+ # Returns true if the host have a localhost ::1 IPv6.
58
+ def self.local_ipv6?
59
+ return @@has_local_ipv6 if defined?(@@has_local_ipv6)
60
+ begin
61
+ get_my_ipv6_address "::1"
62
+ @@has_local_ipv6 = true
63
+ rescue
64
+ @@has_local_ipv6 = false
65
+ end
66
+ end
67
+
68
+ # Returns true if the host have a public IPv6 and stores it in
69
+ # @@public_ipv6.
70
+ def self.public_ipv6?
71
+ return @@has_public_ipv6 if defined?(@@has_public_ipv6)
72
+ begin
73
+ @@public_ipv6 = get_my_ipv6_address "2001::1"
74
+ @@has_public_ipv6 = true
75
+ rescue
76
+ @@has_public_ipv6 = false
77
+ end
78
+ end
79
+
80
+ # Returns an array with the localhost addresses (IPv4 and/or IPv6).
81
+ def local_ips
82
+ return @@local_ips if defined?(@@local_ips)
83
+ @@local_ips = []
84
+ @@local_ips << "127.0.0.1" if self.class.local_ipv4?
85
+ @@local_ips << "::1" if self.class.local_ipv6?
86
+ @@local_ips
87
+ end
88
+
89
+ def exception_class
90
+ jruby? ? NativeException : RuntimeError
91
+ end
92
+
93
+ module PlatformHelper
94
+ # http://blog.emptyway.com/2009/11/03/proper-way-to-detect-windows-platform-in-ruby/
95
+ def windows?
96
+ RbConfig::CONFIG['host_os'] =~ /mswin|mingw/
97
+ end
98
+
99
+ def solaris?
100
+ RUBY_PLATFORM =~ /solaris/
101
+ end
102
+
103
+ # http://stackoverflow.com/questions/1342535/how-can-i-tell-if-im-running-from-jruby-vs-ruby/1685970#1685970
104
+ def jruby?
105
+ defined? JRUBY_VERSION
106
+ end
107
+
108
+ def rbx?
109
+ defined?(RUBY_ENGINE) && RUBY_ENGINE == 'rbx'
110
+ end
111
+ end
112
+
113
+ include PlatformHelper
114
+ extend PlatformHelper
115
+
116
+ # Tests run significantly slower on windows. YMMV
117
+ TIMEOUT_INTERVAL = windows? ? 1 : 0.25
118
+
119
+ def silent
120
+ backup, $VERBOSE = $VERBOSE, nil
121
+ begin
122
+ yield
123
+ ensure
124
+ $VERBOSE = backup
125
+ end
126
+ end
127
+
128
+
129
+ private
130
+
131
+ def self.get_my_ipv4_address ip
132
+ orig, Socket.do_not_reverse_lookup = Socket.do_not_reverse_lookup, true # turn off reverse DNS resolution temporarily
133
+ UDPSocket.open(Socket::AF_INET) do |s|
134
+ s.connect ip, 1
135
+ s.addr.last
136
+ end
137
+ ensure
138
+ Socket.do_not_reverse_lookup = orig
139
+ end
140
+
141
+ def self.get_my_ipv6_address ip
142
+ orig, Socket.do_not_reverse_lookup = Socket.do_not_reverse_lookup, true # turn off reverse DNS resolution temporarily
143
+ UDPSocket.open(Socket::AF_INET6) do |s|
144
+ s.connect ip, 1
145
+ s.addr.last
146
+ end
147
+ ensure
148
+ Socket.do_not_reverse_lookup = orig
149
+ end
150
+
151
+ end
@@ -0,0 +1,151 @@
1
+ require 'em_test_helper'
2
+ require 'socket'
3
+
4
+ class TestAttach < Test::Unit::TestCase
5
+ class EchoServer < EM::Connection
6
+ def receive_data data
7
+ $received_data << data
8
+ send_data data
9
+ end
10
+ end
11
+
12
+ class EchoClient < EM::Connection
13
+ def initialize socket
14
+ self.notify_readable = true
15
+ @socket = socket
16
+ @socket.write("abc\n")
17
+ end
18
+
19
+ def notify_readable
20
+ $read = @socket.readline
21
+ $fd = detach
22
+ end
23
+
24
+ def unbind
25
+ EM.next_tick do
26
+ @socket.write("def\n")
27
+ EM.add_timer(0.1) { EM.stop }
28
+ end
29
+ end
30
+ end
31
+
32
+ def setup
33
+ @port = next_port
34
+ $read, $r, $w, $fd = nil
35
+ $received_data = ""
36
+ end
37
+
38
+ def teardown
39
+ [$r, $w].each do |io|
40
+ io.close rescue nil
41
+ end
42
+ $received_data = nil
43
+ end
44
+
45
+ def test_attach
46
+ socket = nil
47
+
48
+ EM.run {
49
+ EM.start_server "127.0.0.1", @port, EchoServer
50
+ socket = TCPSocket.new "127.0.0.1", @port
51
+ EM.watch socket, EchoClient, socket
52
+ }
53
+
54
+ assert_equal $read, "abc\n"
55
+ unless jruby? # jruby filenos are not real
56
+ assert_equal $fd, socket.fileno
57
+ end
58
+ assert_equal false, socket.closed?
59
+ assert_equal socket.readline, "def\n"
60
+ end
61
+
62
+ module PipeWatch
63
+ def notify_readable
64
+ $read = $r.readline
65
+ EM.stop
66
+ end
67
+ end
68
+
69
+ def test_attach_server
70
+ omit_if(jruby?)
71
+ $before = TCPServer.new("127.0.0.1", @port)
72
+ sig = nil
73
+ EM.run {
74
+ sig = EM.attach_server $before, EchoServer
75
+
76
+ handler = Class.new(EM::Connection) do
77
+ def initialize
78
+ send_data "hello world"
79
+ close_connection_after_writing
80
+ EM.add_timer(0.1) { EM.stop }
81
+ end
82
+ end
83
+ EM.connect("127.0.0.1", @port, handler)
84
+ }
85
+
86
+ assert_equal false, $before.closed?
87
+ assert_equal "hello world", $received_data
88
+ assert sig.is_a?(Integer)
89
+ end
90
+
91
+ def test_attach_pipe
92
+ EM.run{
93
+ $r, $w = IO.pipe
94
+ EM.watch $r, PipeWatch do |c|
95
+ c.notify_readable = true
96
+ end
97
+ $w.write("ghi\n")
98
+ }
99
+
100
+ assert_equal $read, "ghi\n"
101
+ end
102
+
103
+ def test_set_readable
104
+ before, after = nil
105
+
106
+ EM.run{
107
+ $r, $w = IO.pipe
108
+ c = EM.watch $r, PipeWatch do |con|
109
+ con.notify_readable = false
110
+ end
111
+
112
+ EM.next_tick{
113
+ before = c.notify_readable?
114
+ c.notify_readable = true
115
+ after = c.notify_readable?
116
+ }
117
+
118
+ $w.write("jkl\n")
119
+ }
120
+
121
+ assert !before
122
+ assert after
123
+ assert_equal $read, "jkl\n"
124
+ end
125
+
126
+ def test_read_write_pipe
127
+ result = nil
128
+
129
+ pipe_reader = Module.new do
130
+ define_method :receive_data do |data|
131
+ result = data
132
+ EM.stop
133
+ end
134
+ end
135
+
136
+ r,w = IO.pipe
137
+
138
+ EM.run {
139
+ EM.attach r, pipe_reader
140
+ writer = EM.attach(w)
141
+ writer.send_data 'ghi'
142
+
143
+ # XXX: Process will hang in Windows without this line
144
+ writer.close_connection_after_writing
145
+ }
146
+
147
+ assert_equal "ghi", result
148
+ ensure
149
+ [r,w].each {|io| io.close rescue nil }
150
+ end
151
+ end
@@ -0,0 +1,283 @@
1
+ require 'em_test_helper'
2
+ require 'socket'
3
+
4
+ class TestBasic < Test::Unit::TestCase
5
+ def setup
6
+ @port = next_port
7
+ end
8
+
9
+ def test_connection_class_cache
10
+ mod = Module.new
11
+ a, b = nil, nil
12
+ EM.run {
13
+ EM.start_server '127.0.0.1', @port, mod
14
+ a = EM.connect '127.0.0.1', @port, mod
15
+ b = EM.connect '127.0.0.1', @port, mod
16
+ EM.stop
17
+ }
18
+ assert_equal a.class, b.class
19
+ assert_kind_of EM::Connection, a
20
+ end
21
+
22
+ #-------------------------------------
23
+
24
+
25
+ def test_em
26
+ assert_nothing_raised do
27
+ EM.run {
28
+ setup_timeout
29
+ EM.add_timer 0 do
30
+ EM.stop
31
+ end
32
+ }
33
+ end
34
+ end
35
+
36
+ #-------------------------------------
37
+
38
+ def test_timer
39
+ assert_nothing_raised do
40
+ EM.run {
41
+ setup_timeout
42
+ n = 0
43
+ EM.add_periodic_timer(0.1) {
44
+ n += 1
45
+ EM.stop if n == 2
46
+ }
47
+ }
48
+ end
49
+ end
50
+
51
+ #-------------------------------------
52
+
53
+ # This test once threw an already-running exception.
54
+ module Trivial
55
+ def post_init
56
+ EM.stop
57
+ end
58
+ end
59
+
60
+ def test_server
61
+ assert_nothing_raised do
62
+ EM.run {
63
+ setup_timeout
64
+ EM.start_server "127.0.0.1", @port, Trivial
65
+ EM.connect "127.0.0.1", @port
66
+ }
67
+ end
68
+ end
69
+
70
+ #--------------------------------------
71
+
72
+ # EM#run_block starts the reactor loop, runs the supplied block, and then STOPS
73
+ # the loop automatically. Contrast with EM#run, which keeps running the reactor
74
+ # even after the supplied block completes.
75
+ def test_run_block
76
+ assert !EM.reactor_running?
77
+ a = nil
78
+ EM.run_block { a = "Worked" }
79
+ assert a
80
+ assert !EM.reactor_running?
81
+ end
82
+
83
+ class UnbindError < EM::Connection
84
+ ERR = Class.new(StandardError)
85
+ def initialize *args
86
+ super
87
+ end
88
+ def connection_completed
89
+ close_connection_after_writing
90
+ end
91
+ def unbind
92
+ raise ERR
93
+ end
94
+ end
95
+
96
+ def test_unbind_error_during_stop
97
+ assert_raises( UnbindError::ERR ) {
98
+ EM.run {
99
+ EM.start_server "127.0.0.1", @port
100
+ EM.connect "127.0.0.1", @port, UnbindError do
101
+ EM.stop
102
+ end
103
+ }
104
+ }
105
+ end
106
+
107
+ def test_unbind_error
108
+ EM.run {
109
+ EM.error_handler do |e|
110
+ assert(e.is_a?(UnbindError::ERR))
111
+ EM.stop
112
+ end
113
+ EM.start_server "127.0.0.1", @port
114
+ EM.connect "127.0.0.1", @port, UnbindError
115
+ }
116
+ end
117
+
118
+ module BrsTestSrv
119
+ def receive_data data
120
+ $received << data
121
+ end
122
+ def unbind
123
+ EM.stop
124
+ end
125
+ end
126
+ module BrsTestCli
127
+ def post_init
128
+ send_data $sent
129
+ close_connection_after_writing
130
+ end
131
+ end
132
+
133
+ # From ticket #50
134
+ def test_byte_range_send
135
+ $received = ''
136
+ $sent = (0..255).to_a.pack('C*')
137
+ EM::run {
138
+ EM::start_server "127.0.0.1", @port, BrsTestSrv
139
+ EM::connect "127.0.0.1", @port, BrsTestCli
140
+
141
+ setup_timeout
142
+ }
143
+ assert_equal($sent, $received)
144
+ end
145
+
146
+ def test_bind_connect
147
+ pend('FIXME: this test is broken on Windows') if windows?
148
+
149
+ local_ip = UDPSocket.open {|s| s.connect('google.com', 80); s.addr.last }
150
+
151
+ bind_port = next_port
152
+
153
+ port, ip = nil
154
+ bound_server = Module.new do
155
+ define_method :post_init do
156
+ begin
157
+ port, ip = Socket.unpack_sockaddr_in(get_peername)
158
+ ensure
159
+ EM.stop
160
+ end
161
+ end
162
+ end
163
+
164
+ EM.run do
165
+ setup_timeout
166
+ EM.start_server "127.0.0.1", @port, bound_server
167
+ EM.bind_connect local_ip, bind_port, "127.0.0.1", @port
168
+ end
169
+
170
+ assert_equal bind_port, port
171
+ assert_equal local_ip, ip
172
+ end
173
+
174
+ def test_reactor_thread?
175
+ assert !EM.reactor_thread?
176
+ EM.run { assert EM.reactor_thread?; EM.stop }
177
+ assert !EM.reactor_thread?
178
+ end
179
+
180
+ def test_schedule_on_reactor_thread
181
+ x = false
182
+ EM.run do
183
+ EM.schedule { x = true }
184
+ EM.stop
185
+ end
186
+ assert x
187
+ end
188
+
189
+ def test_schedule_from_thread
190
+ x = false
191
+ EM.run do
192
+ Thread.new { EM.schedule { x = true; EM.stop } }.join
193
+ end
194
+ assert x
195
+ end
196
+
197
+ def test_set_heartbeat_interval
198
+ omit_if(jruby?)
199
+ interval = 0.5
200
+ EM.run {
201
+ EM.set_heartbeat_interval interval
202
+ $interval = EM.get_heartbeat_interval
203
+ EM.stop
204
+ }
205
+ assert_equal(interval, $interval)
206
+ end
207
+
208
+ module PostInitRaiser
209
+ ERR = Class.new(StandardError)
210
+ def post_init
211
+ raise ERR
212
+ end
213
+ end
214
+
215
+ def test_bubble_errors_from_post_init
216
+ assert_raises(PostInitRaiser::ERR) do
217
+ EM.run do
218
+ EM.start_server "127.0.0.1", @port
219
+ EM.connect "127.0.0.1", @port, PostInitRaiser
220
+ end
221
+ end
222
+ end
223
+
224
+ module InitializeRaiser
225
+ ERR = Class.new(StandardError)
226
+ def initialize
227
+ raise ERR
228
+ end
229
+ end
230
+
231
+ def test_bubble_errors_from_initialize
232
+ assert_raises(InitializeRaiser::ERR) do
233
+ EM.run do
234
+ EM.start_server "127.0.0.1", @port
235
+ EM.connect "127.0.0.1", @port, InitializeRaiser
236
+ end
237
+ end
238
+ end
239
+
240
+ def test_schedule_close
241
+ omit_if(jruby?)
242
+ localhost, port = '127.0.0.1', 9000
243
+ timer_ran = false
244
+ num_close_scheduled = nil
245
+ EM.run do
246
+ assert_equal 0, EM.num_close_scheduled
247
+ EM.add_timer(1) { timer_ran = true; EM.stop }
248
+ EM.start_server localhost, port do |s|
249
+ s.close_connection
250
+ num_close_scheduled = EM.num_close_scheduled
251
+ end
252
+ EM.connect localhost, port do |c|
253
+ def c.unbind
254
+ EM.stop
255
+ end
256
+ end
257
+ end
258
+ assert !timer_ran
259
+ assert_equal 1, num_close_scheduled
260
+ end
261
+
262
+ def test_error_handler_idempotent # issue 185
263
+ errors = []
264
+ ticks = []
265
+ EM.error_handler do |e|
266
+ errors << e
267
+ end
268
+
269
+ EM.run do
270
+ EM.next_tick do
271
+ ticks << :first
272
+ raise
273
+ end
274
+ EM.next_tick do
275
+ ticks << :second
276
+ end
277
+ EM.add_timer(0.001) { EM.stop }
278
+ end
279
+
280
+ assert_equal 1, errors.size
281
+ assert_equal [:first, :second], ticks
282
+ end
283
+ end