libc-eventmachine 0.12.5.42

Sign up to get free protection for your applications and to get access to all the features.
Files changed (131) hide show
  1. data/Rakefile +195 -0
  2. data/docs/COPYING +60 -0
  3. data/docs/ChangeLog +211 -0
  4. data/docs/DEFERRABLES +138 -0
  5. data/docs/EPOLL +141 -0
  6. data/docs/GNU +281 -0
  7. data/docs/INSTALL +15 -0
  8. data/docs/KEYBOARD +38 -0
  9. data/docs/LEGAL +25 -0
  10. data/docs/LIGHTWEIGHT_CONCURRENCY +72 -0
  11. data/docs/PURE_RUBY +77 -0
  12. data/docs/README +74 -0
  13. data/docs/RELEASE_NOTES +96 -0
  14. data/docs/SMTP +9 -0
  15. data/docs/SPAWNED_PROCESSES +93 -0
  16. data/docs/TODO +10 -0
  17. data/ext/binder.cpp +126 -0
  18. data/ext/binder.h +48 -0
  19. data/ext/cmain.cpp +582 -0
  20. data/ext/cplusplus.cpp +177 -0
  21. data/ext/ed.cpp +1522 -0
  22. data/ext/ed.h +380 -0
  23. data/ext/em.cpp +1947 -0
  24. data/ext/em.h +186 -0
  25. data/ext/emwin.cpp +300 -0
  26. data/ext/emwin.h +94 -0
  27. data/ext/epoll.cpp +26 -0
  28. data/ext/epoll.h +25 -0
  29. data/ext/eventmachine.h +98 -0
  30. data/ext/eventmachine_cpp.h +96 -0
  31. data/ext/extconf.rb +129 -0
  32. data/ext/fastfilereader/extconf.rb +77 -0
  33. data/ext/fastfilereader/mapper.cpp +214 -0
  34. data/ext/fastfilereader/mapper.h +59 -0
  35. data/ext/fastfilereader/rubymain.cpp +127 -0
  36. data/ext/files.cpp +94 -0
  37. data/ext/files.h +65 -0
  38. data/ext/kb.cpp +82 -0
  39. data/ext/page.cpp +107 -0
  40. data/ext/page.h +51 -0
  41. data/ext/pipe.cpp +351 -0
  42. data/ext/project.h +119 -0
  43. data/ext/rubymain.cpp +858 -0
  44. data/ext/sigs.cpp +89 -0
  45. data/ext/sigs.h +32 -0
  46. data/ext/ssl.cpp +423 -0
  47. data/ext/ssl.h +90 -0
  48. data/java/src/com/rubyeventmachine/Application.java +196 -0
  49. data/java/src/com/rubyeventmachine/Connection.java +74 -0
  50. data/java/src/com/rubyeventmachine/ConnectionFactory.java +37 -0
  51. data/java/src/com/rubyeventmachine/DefaultConnectionFactory.java +46 -0
  52. data/java/src/com/rubyeventmachine/EmReactor.java +408 -0
  53. data/java/src/com/rubyeventmachine/EmReactorException.java +40 -0
  54. data/java/src/com/rubyeventmachine/EventableChannel.java +57 -0
  55. data/java/src/com/rubyeventmachine/EventableDatagramChannel.java +171 -0
  56. data/java/src/com/rubyeventmachine/EventableSocketChannel.java +244 -0
  57. data/java/src/com/rubyeventmachine/PeriodicTimer.java +38 -0
  58. data/java/src/com/rubyeventmachine/Timer.java +54 -0
  59. data/java/src/com/rubyeventmachine/tests/ApplicationTest.java +108 -0
  60. data/java/src/com/rubyeventmachine/tests/ConnectTest.java +124 -0
  61. data/java/src/com/rubyeventmachine/tests/EMTest.java +80 -0
  62. data/java/src/com/rubyeventmachine/tests/TestDatagrams.java +53 -0
  63. data/java/src/com/rubyeventmachine/tests/TestServers.java +74 -0
  64. data/java/src/com/rubyeventmachine/tests/TestTimers.java +89 -0
  65. data/lib/em/deferrable.rb +208 -0
  66. data/lib/em/eventable.rb +39 -0
  67. data/lib/em/future.rb +62 -0
  68. data/lib/em/messages.rb +66 -0
  69. data/lib/em/processes.rb +68 -0
  70. data/lib/em/spawnable.rb +88 -0
  71. data/lib/em/streamer.rb +112 -0
  72. data/lib/eventmachine.rb +1920 -0
  73. data/lib/eventmachine_version.rb +31 -0
  74. data/lib/evma/callback.rb +32 -0
  75. data/lib/evma/container.rb +75 -0
  76. data/lib/evma/factory.rb +77 -0
  77. data/lib/evma/protocol.rb +87 -0
  78. data/lib/evma/reactor.rb +48 -0
  79. data/lib/evma.rb +32 -0
  80. data/lib/jeventmachine.rb +140 -0
  81. data/lib/pr_eventmachine.rb +1017 -0
  82. data/lib/protocols/buftok.rb +127 -0
  83. data/lib/protocols/header_and_content.rb +129 -0
  84. data/lib/protocols/httpcli2.rb +803 -0
  85. data/lib/protocols/httpclient.rb +270 -0
  86. data/lib/protocols/line_and_text.rb +126 -0
  87. data/lib/protocols/linetext2.rb +161 -0
  88. data/lib/protocols/memcache.rb +293 -0
  89. data/lib/protocols/postgres.rb +261 -0
  90. data/lib/protocols/saslauth.rb +179 -0
  91. data/lib/protocols/smtpclient.rb +308 -0
  92. data/lib/protocols/smtpserver.rb +556 -0
  93. data/lib/protocols/stomp.rb +153 -0
  94. data/lib/protocols/tcptest.rb +57 -0
  95. data/tasks/cpp.rake +77 -0
  96. data/tasks/project.rake +78 -0
  97. data/tasks/tests.rake +193 -0
  98. data/tests/test_attach.rb +83 -0
  99. data/tests/test_basic.rb +231 -0
  100. data/tests/test_bind.rb +73 -0
  101. data/tests/test_connection_count.rb +35 -0
  102. data/tests/test_defer.rb +47 -0
  103. data/tests/test_epoll.rb +163 -0
  104. data/tests/test_error_handler.rb +32 -0
  105. data/tests/test_errors.rb +82 -0
  106. data/tests/test_eventables.rb +77 -0
  107. data/tests/test_exc.rb +58 -0
  108. data/tests/test_futures.rb +214 -0
  109. data/tests/test_handler_check.rb +37 -0
  110. data/tests/test_hc.rb +218 -0
  111. data/tests/test_httpclient.rb +215 -0
  112. data/tests/test_httpclient2.rb +155 -0
  113. data/tests/test_kb.rb +61 -0
  114. data/tests/test_ltp.rb +188 -0
  115. data/tests/test_ltp2.rb +320 -0
  116. data/tests/test_next_tick.rb +109 -0
  117. data/tests/test_processes.rb +56 -0
  118. data/tests/test_pure.rb +129 -0
  119. data/tests/test_running.rb +47 -0
  120. data/tests/test_sasl.rb +74 -0
  121. data/tests/test_send_file.rb +243 -0
  122. data/tests/test_servers.rb +80 -0
  123. data/tests/test_smtpclient.rb +83 -0
  124. data/tests/test_smtpserver.rb +93 -0
  125. data/tests/test_spawn.rb +329 -0
  126. data/tests/test_ssl_args.rb +68 -0
  127. data/tests/test_ssl_methods.rb +50 -0
  128. data/tests/test_timers.rb +148 -0
  129. data/tests/test_ud.rb +43 -0
  130. data/tests/testem.rb +31 -0
  131. metadata +230 -0
@@ -0,0 +1,231 @@
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 File.expand_path(File.dirname(__FILE__) + "/../lib")
28
+ require 'eventmachine'
29
+ require 'test/unit'
30
+
31
+ class TestBasic < Test::Unit::TestCase
32
+
33
+ def setup
34
+ assert(!EM.reactor_running?)
35
+ end
36
+
37
+ def teardown
38
+ assert(!EM.reactor_running?)
39
+ end
40
+
41
+ #-------------------------------------
42
+
43
+ def test_libtype
44
+ lt = EventMachine.library_type
45
+ em_lib = (ENV["EVENTMACHINE_LIBRARY"] || $eventmachine_library || :xxx).to_sym
46
+
47
+ # Running from test runner, under jruby.
48
+ if RUBY_PLATFORM == 'java'
49
+ unless em_lib == :pure_ruby
50
+ assert_equal( :java, lt )
51
+ return
52
+ end
53
+ end
54
+
55
+ case em_lib
56
+ when :pure_ruby
57
+ assert_equal( :pure_ruby, lt )
58
+ when :extension
59
+ assert_equal( :extension, lt )
60
+ when :java
61
+ assert_equal( :java, lt )
62
+ else
63
+ # Running from jruby as a standalone test.
64
+ if RUBY_PLATFORM == 'java'
65
+ assert_equal( :java, lt )
66
+ else
67
+ assert_equal( :extension, lt )
68
+ end
69
+ end
70
+ end
71
+
72
+ #-------------------------------------
73
+
74
+
75
+ def test_em
76
+ EventMachine.run {
77
+ EventMachine.add_timer 0 do
78
+ EventMachine.stop
79
+ end
80
+ }
81
+ end
82
+
83
+ #-------------------------------------
84
+
85
+ def test_timer
86
+ n = 0
87
+ EventMachine.run {
88
+ EventMachine.add_periodic_timer(0.1) {
89
+ n += 1
90
+ EventMachine.stop if n == 2
91
+ }
92
+ }
93
+ end
94
+
95
+ #-------------------------------------
96
+
97
+ # This test once threw an already-running exception.
98
+ module Trivial
99
+ def post_init
100
+ EventMachine.stop
101
+ end
102
+ end
103
+
104
+ def test_server
105
+ EventMachine.run {
106
+ EventMachine.start_server "localhost", 9000, Trivial
107
+ EventMachine.connect "localhost", 9000
108
+ }
109
+ assert( true ) # make sure it halts
110
+ end
111
+
112
+ #--------------------------------------
113
+
114
+ # EventMachine#run_block starts the reactor loop, runs the supplied block, and then STOPS
115
+ # the loop automatically. Contrast with EventMachine#run, which keeps running the reactor
116
+ # even after the supplied block completes.
117
+ def test_run_block
118
+ assert !EM.reactor_running?
119
+ a = nil
120
+ EM.run_block { a = "Worked" }
121
+ assert a
122
+ assert !EM.reactor_running?
123
+ end
124
+
125
+
126
+ #--------------------------------------
127
+
128
+ # TODO! This is an unfinished edge case.
129
+ # EM mishandles uncaught Ruby exceptions that fire from within #unbind handlers.
130
+ # A uncaught Ruby exception results in a call to EM::release_machine (which is in an ensure
131
+ # block in EM::run). But if EM is processing an unbind request, the release_machine call
132
+ # will cause a segmentation fault.
133
+ #
134
+
135
+ TestHost = "127.0.0.1"
136
+ TestPort = 9070
137
+
138
+ class UnbindError < EM::Connection
139
+ def initialize *args
140
+ super
141
+ end
142
+ def connection_completed
143
+ close_connection_after_writing
144
+ end
145
+ def unbind
146
+ raise "Blooey"
147
+ end
148
+ end
149
+
150
+ def xxx_test_unbind_error
151
+ assert_raises( RuntimeError ) {
152
+ EM.run {
153
+ EM.start_server TestHost, TestPort
154
+ EM.connect TestHost, TestPort, UnbindError
155
+ }
156
+ }
157
+ end
158
+
159
+ #------------------------------------
160
+ #
161
+ # TODO. This is an unfinished bug fix.
162
+ # This case was originally reported by Dan Aquino. If you throw a Ruby exception
163
+ # in a post_init handler, it gets rethrown as a confusing reactor exception.
164
+ # The problem is in eventmachine.rb, which calls post_init within the private
165
+ # initialize method of the EM::Connection class. This happens in both the EM::connect
166
+ # method and in the code that responds to connection-accepted events.
167
+ # What happens is that we instantiate the new connection object, which calls
168
+ # initialize, and then after initialize returns, we stick the new connection object
169
+ # into EM's @conns hashtable.
170
+ # But the problem is that Connection::initialize calls #post_init before it returns,
171
+ # and this may be user-written code that may throw an uncaught Ruby exception.
172
+ # If that happens, the reactor will abort, and it will then try to run down open
173
+ # connections. Because @conns never got a chance to properly reflect the new connection
174
+ # (because initialize never returned), we throw a ConnectionNotBound error
175
+ # (eventmachine.rb line 1080).
176
+ # When the bug is fixed, activate this test case.
177
+ #
178
+
179
+ class PostInitError < EM::Connection
180
+ def post_init
181
+ aaa bbb # should produce a Ruby exception
182
+ end
183
+ end
184
+ # This test causes issues, the machine becomes unreleasable after
185
+ # release_machine suffers an exception in event_callback.
186
+ def xxx_test_post_init_error
187
+ assert_raises( EventMachine::ConnectionNotBound ) {
188
+ EM.run {
189
+ EM::Timer.new(1) {EM.stop}
190
+ EM.start_server TestHost, TestPort
191
+ EM.connect TestHost, TestPort, PostInitError
192
+ }
193
+ }
194
+ EM.run {
195
+ EM.stop
196
+ }
197
+ assert !EM.reactor_running?
198
+ end
199
+
200
+ module BrsTestSrv
201
+ def receive_data data
202
+ $received << data
203
+ end
204
+ def unbind
205
+ EM.stop
206
+ end
207
+ end
208
+ module BrsTestCli
209
+ def post_init
210
+ send_data $sent
211
+ close_connection_after_writing
212
+ end
213
+ end
214
+
215
+ # From ticket #50
216
+ def test_byte_range_send
217
+ $received = ''
218
+ $sent = (0..255).to_a.pack('C*')
219
+ EM::run {
220
+
221
+ EM::start_server TestHost, TestPort, BrsTestSrv
222
+
223
+ EM::connect TestHost, TestPort, BrsTestCli
224
+
225
+ EM::add_timer(0.5) { assert(false, 'test timed out'); EM.stop; Kernel.warn "test timed out!" }
226
+ }
227
+ assert_equal($sent, $received)
228
+ end
229
+
230
+ end
231
+
@@ -0,0 +1,73 @@
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 File.expand_path(File.dirname(__FILE__) + "/../lib")
28
+ require 'eventmachine'
29
+ require 'test/unit'
30
+
31
+ class TestBind < Test::Unit::TestCase
32
+ TestHost = '127.0.0.1'
33
+ TestPort = 9621
34
+ def setup
35
+ assert(!EM.reactor_running?)
36
+ end
37
+
38
+ def teardown
39
+ assert(!EM.reactor_running?)
40
+ end
41
+
42
+ module BrsTestSrv
43
+ def receive_data data
44
+ $received << data
45
+ end
46
+ def unbind
47
+ EM.stop
48
+ end
49
+ end
50
+ module BrsTestCli
51
+ def post_init
52
+ send_data $sent
53
+ close_connection_after_writing
54
+ end
55
+ end
56
+
57
+ def test_bind
58
+ $received = ''
59
+ $sent = (0..255).to_a.pack('C*')
60
+ EM::run {
61
+
62
+ EM::start_server TestHost, TestPort, BrsTestSrv
63
+
64
+ EM::connect2 TestHost, TestPort, BrsTestCli, :bind => "127.0.0.1"
65
+ assert_raise(RuntimeError) { EM::connect2 TestHost, TestPort, BrsTestCli, :bind_host => "128.0.0.1" }
66
+
67
+ EM::add_timer(0.5) { assert(false, 'test timed out'); EM.stop; Kernel.warn "test timed out!" }
68
+ }
69
+ assert_equal($sent, $received)
70
+ end
71
+
72
+ end
73
+
@@ -0,0 +1,35 @@
1
+ $:.unshift "../lib"
2
+ require 'eventmachine'
3
+ require 'test/unit'
4
+
5
+ class TestConnectionCount < Test::Unit::TestCase
6
+
7
+ def test_idle_connection_count
8
+ EM.run {
9
+ $count = EM.connection_count
10
+ EM.stop_event_loop
11
+ }
12
+
13
+ assert_equal(0, $count)
14
+ end
15
+
16
+ def test_with_some_connections
17
+ EM.run {
18
+ EM.start_server("127.0.0.1", 9999)
19
+ EM.connect("127.0.0.1", 9999)
20
+ $first_tick = EM.connection_count
21
+ EM.next_tick {
22
+ $second_tick = EM.connection_count
23
+ EM.next_tick {
24
+ $third_tick = EM.connection_count
25
+ EM.stop_event_loop
26
+ }
27
+ }
28
+ }
29
+
30
+ assert_equal(0, $first_tick)
31
+ assert_equal(2, $second_tick)
32
+ assert_equal(3, $third_tick)
33
+ end
34
+
35
+ end
@@ -0,0 +1,47 @@
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'
30
+
31
+ class TestDeferUsage < Test::Unit::TestCase
32
+
33
+ def test_defers
34
+ n = 0
35
+ n_times = 20
36
+ EM.run {
37
+ n_times.times {
38
+ work_proc = proc { n += 1 }
39
+ callback = proc { EM.stop if n == n_times }
40
+ EM.defer work_proc, callback
41
+ }
42
+ }
43
+ assert_equal( n, n_times )
44
+ end unless RUBY_VERSION >= '1.9.0'
45
+
46
+ end
47
+
@@ -0,0 +1,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
+ def test_descriptors
78
+ EM.epoll
79
+ s = EM.set_descriptor_table_size 60000
80
+ EM.run {
81
+ EM.start_server "127.0.0.1", 9800, TestEchoServer
82
+ $n = 0
83
+ $max = 0
84
+ 100.times {
85
+ EM.connect("127.0.0.1", 9800, TestEchoClient) {$n += 1}
86
+ }
87
+ }
88
+ assert_equal(0, $n)
89
+ assert_equal(100, $max)
90
+ end
91
+
92
+ def test_defer
93
+ n = 0
94
+ work_proc = proc {n += 1}
95
+ callback_proc = proc {EM.stop}
96
+ EM.epoll
97
+ EM.run {
98
+ EM.defer work_proc, callback_proc
99
+ }
100
+ assert_equal( 1, n )
101
+ end unless RUBY_VERSION >= '1.9.0'
102
+
103
+
104
+ module TestDatagramServer
105
+ def receive_data dgm
106
+ $in = dgm
107
+ send_data "abcdefghij"
108
+ end
109
+ end
110
+ module TestDatagramClient
111
+ def post_init
112
+ send_datagram "1234567890", "127.0.0.1", 9500
113
+ end
114
+ def receive_data dgm
115
+ $out = dgm
116
+ EM.stop
117
+ end
118
+ end
119
+
120
+ def test_datagrams
121
+ $in = $out = ""
122
+ EM.epoll
123
+ EM.run {
124
+ EM.open_datagram_socket "127.0.0.1", 9500, TestDatagramServer
125
+ EM.open_datagram_socket "127.0.0.1", 0, TestDatagramClient
126
+ }
127
+ assert_equal( "1234567890", $in )
128
+ assert_equal( "abcdefghij", $out )
129
+ end
130
+
131
+
132
+
133
+
134
+ def test_unix_domain
135
+ fn = "/tmp/xxx.chain"
136
+ EM.epoll
137
+ s = EM.set_descriptor_table_size 60000
138
+ EM.run {
139
+ # The pure-Ruby version won't let us open the socket if the node already exists.
140
+ # Not sure, that actually may be correct and the compiled version is wrong.
141
+ # Pure Ruby also oddly won't let us make that many connections. This test used
142
+ # to run 100 times. Not sure where that lower connection-limit is coming from in
143
+ # pure Ruby.
144
+ # Let's not sweat the Unix-ness of the filename, since this test can't possibly
145
+ # work on Windows anyway.
146
+ #
147
+ File.unlink(fn) if File.exist?(fn)
148
+ EM.start_unix_domain_server fn, TestEchoServer
149
+ $n = 0
150
+ $max = 0
151
+ 50.times {
152
+ EM.connect_unix_domain(fn, TestEchoClient) {$n += 1}
153
+ }
154
+ EM::add_timer(1) { $stderr.puts("test_unix_domain timed out!"); EM::stop }
155
+ }
156
+ assert_equal(0, $n)
157
+ assert_equal(50, $max)
158
+ ensure
159
+ File.unlink(fn) if File.exist?(fn)
160
+ end
161
+
162
+ end
163
+
@@ -0,0 +1,32 @@
1
+ $:.unshift "../lib"
2
+ require 'eventmachine'
3
+ require 'test/unit'
4
+
5
+ class TestErrorHandler < Test::Unit::TestCase
6
+ def test_error_handler
7
+ error = nil
8
+ EM.error_handler{ |e|
9
+ error = e
10
+ EM.error_handler(nil)
11
+ EM.stop
12
+ }
13
+
14
+ EM.run{
15
+ EM.add_timer(0){
16
+ raise 'test'
17
+ }
18
+ }
19
+
20
+ assert_equal error.message, 'test'
21
+ end
22
+
23
+ def test_without_error_handler
24
+ assert_raise RuntimeError do
25
+ EM.run{
26
+ EM.add_timer(0){
27
+ raise 'test'
28
+ }
29
+ }
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,82 @@
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
+
28
+ ###### THIS TEST IS NOW OBSOLETE.
29
+ ###### As of 27Dec07, the hookable error handling is obsolete because
30
+ ###### of its performance impact.
31
+
32
+
33
+ $:.unshift "../lib"
34
+ require 'eventmachine'
35
+ require 'test/unit'
36
+
37
+ class TestErrors < Test::Unit::TestCase
38
+
39
+ Localhost = "127.0.0.1"
40
+ Localport = 9801
41
+
42
+ def setup
43
+ end
44
+
45
+ def 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
+
52
+ def test_a
53
+ end
54
+
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
+
68
+ end
69
+
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
+ end
82
+