smparkes-eventmachine 0.12.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (158) hide show
  1. data/.gitignore +15 -0
  2. data/README +81 -0
  3. data/Rakefile +374 -0
  4. data/docs/COPYING +60 -0
  5. data/docs/ChangeLog +211 -0
  6. data/docs/DEFERRABLES +133 -0
  7. data/docs/EPOLL +141 -0
  8. data/docs/GNU +281 -0
  9. data/docs/INSTALL +13 -0
  10. data/docs/KEYBOARD +38 -0
  11. data/docs/LEGAL +25 -0
  12. data/docs/LIGHTWEIGHT_CONCURRENCY +70 -0
  13. data/docs/PURE_RUBY +75 -0
  14. data/docs/RELEASE_NOTES +94 -0
  15. data/docs/SMTP +2 -0
  16. data/docs/SPAWNED_PROCESSES +89 -0
  17. data/docs/TODO +8 -0
  18. data/eventmachine.gemspec +40 -0
  19. data/examples/ex_channel.rb +43 -0
  20. data/examples/ex_queue.rb +2 -0
  21. data/examples/helper.rb +2 -0
  22. data/ext/binder.cpp +125 -0
  23. data/ext/binder.h +46 -0
  24. data/ext/cmain.cpp +827 -0
  25. data/ext/cplusplus.cpp +202 -0
  26. data/ext/ed.cpp +1901 -0
  27. data/ext/ed.h +424 -0
  28. data/ext/em.cpp +2288 -0
  29. data/ext/em.h +229 -0
  30. data/ext/emwin.cpp +300 -0
  31. data/ext/emwin.h +94 -0
  32. data/ext/epoll.cpp +26 -0
  33. data/ext/epoll.h +25 -0
  34. data/ext/eventmachine.h +122 -0
  35. data/ext/eventmachine_cpp.h +96 -0
  36. data/ext/extconf.rb +150 -0
  37. data/ext/fastfilereader/extconf.rb +85 -0
  38. data/ext/fastfilereader/mapper.cpp +214 -0
  39. data/ext/fastfilereader/mapper.h +59 -0
  40. data/ext/fastfilereader/rubymain.cpp +127 -0
  41. data/ext/files.cpp +94 -0
  42. data/ext/files.h +65 -0
  43. data/ext/kb.cpp +81 -0
  44. data/ext/page.cpp +107 -0
  45. data/ext/page.h +51 -0
  46. data/ext/pipe.cpp +349 -0
  47. data/ext/project.h +156 -0
  48. data/ext/rubymain.cpp +1194 -0
  49. data/ext/sigs.cpp +89 -0
  50. data/ext/sigs.h +32 -0
  51. data/ext/ssl.cpp +460 -0
  52. data/ext/ssl.h +94 -0
  53. data/java/.classpath +8 -0
  54. data/java/.project +17 -0
  55. data/java/src/com/rubyeventmachine/EmReactor.java +570 -0
  56. data/java/src/com/rubyeventmachine/EmReactorException.java +40 -0
  57. data/java/src/com/rubyeventmachine/EventableChannel.java +69 -0
  58. data/java/src/com/rubyeventmachine/EventableDatagramChannel.java +189 -0
  59. data/java/src/com/rubyeventmachine/EventableSocketChannel.java +364 -0
  60. data/java/src/com/rubyeventmachine/application/Application.java +194 -0
  61. data/java/src/com/rubyeventmachine/application/Connection.java +74 -0
  62. data/java/src/com/rubyeventmachine/application/ConnectionFactory.java +37 -0
  63. data/java/src/com/rubyeventmachine/application/DefaultConnectionFactory.java +46 -0
  64. data/java/src/com/rubyeventmachine/application/PeriodicTimer.java +38 -0
  65. data/java/src/com/rubyeventmachine/application/Timer.java +54 -0
  66. data/java/src/com/rubyeventmachine/tests/ApplicationTest.java +109 -0
  67. data/java/src/com/rubyeventmachine/tests/ConnectTest.java +148 -0
  68. data/java/src/com/rubyeventmachine/tests/EMTest.java +80 -0
  69. data/java/src/com/rubyeventmachine/tests/TestDatagrams.java +53 -0
  70. data/java/src/com/rubyeventmachine/tests/TestServers.java +75 -0
  71. data/java/src/com/rubyeventmachine/tests/TestTimers.java +90 -0
  72. data/lib/em/buftok.rb +138 -0
  73. data/lib/em/callback.rb +26 -0
  74. data/lib/em/channel.rb +57 -0
  75. data/lib/em/connection.rb +564 -0
  76. data/lib/em/deferrable.rb +192 -0
  77. data/lib/em/file_watch.rb +54 -0
  78. data/lib/em/future.rb +61 -0
  79. data/lib/em/messages.rb +66 -0
  80. data/lib/em/process_watch.rb +44 -0
  81. data/lib/em/processes.rb +119 -0
  82. data/lib/em/protocols/header_and_content.rb +138 -0
  83. data/lib/em/protocols/httpclient.rb +263 -0
  84. data/lib/em/protocols/httpclient2.rb +590 -0
  85. data/lib/em/protocols/line_and_text.rb +125 -0
  86. data/lib/em/protocols/linetext2.rb +161 -0
  87. data/lib/em/protocols/memcache.rb +323 -0
  88. data/lib/em/protocols/object_protocol.rb +45 -0
  89. data/lib/em/protocols/postgres3.rb +247 -0
  90. data/lib/em/protocols/saslauth.rb +175 -0
  91. data/lib/em/protocols/smtpclient.rb +357 -0
  92. data/lib/em/protocols/smtpserver.rb +547 -0
  93. data/lib/em/protocols/socks4.rb +66 -0
  94. data/lib/em/protocols/stomp.rb +200 -0
  95. data/lib/em/protocols/tcptest.rb +53 -0
  96. data/lib/em/protocols.rb +36 -0
  97. data/lib/em/queue.rb +61 -0
  98. data/lib/em/spawnable.rb +85 -0
  99. data/lib/em/streamer.rb +130 -0
  100. data/lib/em/timers.rb +56 -0
  101. data/lib/em/version.rb +3 -0
  102. data/lib/eventmachine.rb +1592 -0
  103. data/lib/evma/callback.rb +32 -0
  104. data/lib/evma/container.rb +75 -0
  105. data/lib/evma/factory.rb +77 -0
  106. data/lib/evma/protocol.rb +87 -0
  107. data/lib/evma/reactor.rb +48 -0
  108. data/lib/evma.rb +32 -0
  109. data/lib/jeventmachine.rb +257 -0
  110. data/lib/pr_eventmachine.rb +1022 -0
  111. data/setup.rb +1585 -0
  112. data/tasks/cpp.rake_example +77 -0
  113. data/tests/client.crt +31 -0
  114. data/tests/client.key +51 -0
  115. data/tests/test_attach.rb +126 -0
  116. data/tests/test_basic.rb +284 -0
  117. data/tests/test_channel.rb +63 -0
  118. data/tests/test_connection_count.rb +35 -0
  119. data/tests/test_defer.rb +47 -0
  120. data/tests/test_epoll.rb +160 -0
  121. data/tests/test_error_handler.rb +35 -0
  122. data/tests/test_errors.rb +82 -0
  123. data/tests/test_exc.rb +55 -0
  124. data/tests/test_file_watch.rb +49 -0
  125. data/tests/test_futures.rb +198 -0
  126. data/tests/test_get_sock_opt.rb +30 -0
  127. data/tests/test_handler_check.rb +37 -0
  128. data/tests/test_hc.rb +218 -0
  129. data/tests/test_httpclient.rb +218 -0
  130. data/tests/test_httpclient2.rb +153 -0
  131. data/tests/test_inactivity_timeout.rb +50 -0
  132. data/tests/test_kb.rb +60 -0
  133. data/tests/test_ltp.rb +182 -0
  134. data/tests/test_ltp2.rb +317 -0
  135. data/tests/test_next_tick.rb +133 -0
  136. data/tests/test_object_protocol.rb +37 -0
  137. data/tests/test_pause.rb +70 -0
  138. data/tests/test_pending_connect_timeout.rb +48 -0
  139. data/tests/test_process_watch.rb +48 -0
  140. data/tests/test_processes.rb +128 -0
  141. data/tests/test_proxy_connection.rb +92 -0
  142. data/tests/test_pure.rb +125 -0
  143. data/tests/test_queue.rb +44 -0
  144. data/tests/test_running.rb +42 -0
  145. data/tests/test_sasl.rb +72 -0
  146. data/tests/test_send_file.rb +242 -0
  147. data/tests/test_servers.rb +76 -0
  148. data/tests/test_smtpclient.rb +83 -0
  149. data/tests/test_smtpserver.rb +85 -0
  150. data/tests/test_spawn.rb +322 -0
  151. data/tests/test_ssl_args.rb +79 -0
  152. data/tests/test_ssl_methods.rb +50 -0
  153. data/tests/test_ssl_verify.rb +82 -0
  154. data/tests/test_timers.rb +162 -0
  155. data/tests/test_ud.rb +36 -0
  156. data/tests/testem.rb +31 -0
  157. data/web/whatis +7 -0
  158. metadata +237 -0
@@ -0,0 +1,77 @@
1
+ # EventMachine C++ Rakefile Stab Case
2
+ # TODO : track header files as a build dependency...
3
+ # TODO : cross platform support
4
+ # TODO : configure style functionality
5
+ namespace :cpp do
6
+
7
+ require 'rake/clean'
8
+
9
+ # *nix only atm...
10
+ module Cpp
11
+ class <<self
12
+ def cpp; "g++"; end
13
+ def archive; "ar"; end
14
+ def compile file, output, includes=nil, flags=nil
15
+ sh %{#{cpp} #{file} #{includes} #{flags} -c -o #{output}}
16
+ end
17
+ def link file, output, libs=nil, flags=nil
18
+ sh %{#{cpp} #{file} #{libs} #{flags} -o #{output}}
19
+ end
20
+ def static output, files
21
+ sh %{#{archive} cr #{output} #{files}}
22
+ end
23
+ end
24
+ end
25
+
26
+ module EmConfig
27
+ Path = ENV['EVENTMACHINE_SOURCE'] || 'ext'
28
+ Sources = FileList["#{Path}/*.cpp"]
29
+ Sources.delete_if { |s| /ruby/ =~ s }
30
+ Compiled = Sources.sub(%r{^#{Path}/(.*)\.cpp}, "#{Path}/\\1.o")
31
+
32
+ Flags = "-O2 -pipe -fno-common -DOS_UNIX -DWITHOUT_SSL"
33
+ Includes = ""
34
+ Libs = ''
35
+ end
36
+ CLEAN.include(EmConfig::Compiled)
37
+
38
+ rule %r{^#{EmConfig::Path}/.*\.o$} => [proc { |targ|
39
+ targ.sub(%r{^#{EmConfig::Path}/(.*)\.o$}, "#{EmConfig::Path}/\\1.cpp")
40
+ }] do |t|
41
+ Cpp.compile t.source, t.name, EmConfig::Includes, EmConfig::Flags
42
+ end
43
+
44
+ file "#{EmConfig::Path}/libeventmachine.a" => EmConfig::Compiled do |t|
45
+ Cpp.static t.name, EmConfig::Compiled
46
+ end
47
+ CLEAN.include("#{EmConfig::Path}/libeventmachine.a")
48
+
49
+ module AppConfig
50
+ Appname = 'echo_em'
51
+ Sources = FileList['*.cpp']
52
+ Compiled = Sources.sub(%r{^(.*)\.cpp}, '\\1.o')
53
+
54
+ Flags = ["", EmConfig::Flags].join(' ')
55
+ Includes = ["-I. -I#{EmConfig::Path}", EmConfig::Includes].join(' ')
56
+ Libs = ["-L#{EmConfig::Path} -leventmachine", EmConfig::Libs].join(' ')
57
+ end
58
+ CLEAN.include(AppConfig::Compiled)
59
+ CLEAN.include(AppConfig::Appname)
60
+
61
+ rule %r{^.*\.o$} => [proc { |targ|
62
+ targ.sub(%r{^(.*)\.o$}, '\\1.cpp')
63
+ }] do |t|
64
+ Cpp.compile t.source, t.name, AppConfig::Includes, AppConfig::Flags
65
+ end
66
+
67
+ file AppConfig::Appname => ["#{EmConfig::Path}/libeventmachine.a", AppConfig::Compiled] do |t|
68
+ Cpp.link AppConfig::Compiled, t.name, AppConfig::Libs, AppConfig::Flags
69
+ end
70
+
71
+ task :build => AppConfig::Appname
72
+
73
+ task :run => AppConfig::Appname do
74
+ sh "./#{AppConfig::Appname}"
75
+ end
76
+
77
+ end
data/tests/client.crt ADDED
@@ -0,0 +1,31 @@
1
+ -----BEGIN CERTIFICATE-----
2
+ MIIFRDCCAywCAQEwDQYJKoZIhvcNAQEFBQAwaDELMAkGA1UEBhMCRU0xFTATBgNV
3
+ BAgTDEV2ZW50TWFjaGluZTEVMBMGA1UEChMMRXZlbnRNYWNoaW5lMRQwEgYDVQQL
4
+ EwtEZXZlbG9wbWVudDEVMBMGA1UEAxMMRXZlbnRNYWNoaW5lMB4XDTA5MDMyOTAy
5
+ MzE0NloXDTEwMDMyOTAyMzE0NlowaDELMAkGA1UEBhMCRU0xFTATBgNVBAgTDEV2
6
+ ZW50TWFjaGluZTEVMBMGA1UEChMMRXZlbnRNYWNoaW5lMRQwEgYDVQQLEwtEZXZl
7
+ bG9wbWVudDEVMBMGA1UEAxMMRXZlbnRNYWNoaW5lMIICIjANBgkqhkiG9w0BAQEF
8
+ AAOCAg8AMIICCgKCAgEAv1FSOIX1z7CQtVBFlrB0A3/V29T+22STKKmiRWYkKL5b
9
+ +hkrp9IZ5J4phZHgUVM2VDPOO2Oc2PU6dlGGZISg+UPERunTogxQKezCV0vcE9cK
10
+ OwzxCFDRvv5rK8aKMscfBLbNKocAXywuRRQmdxPiVRzbyPrl+qCr/EDLXAX3D77l
11
+ S8n2AwDg19VyI+IgFUE+Dy5e1eLoY6nV+Mq+vNXdn3ttF3t+ngac5pj5Q9h+pD5p
12
+ 67baDHSnf/7cy2fa/LKrLolVHQR9G2K6cEfeM99NtcsMbkoPs4iI3FA05OVTQHXg
13
+ C8C8cRxrb9APl95I/ep65OIaCJgcdYxJ3QD3qOtQo6/NQsGnjbyiUxaEpjfqyT1N
14
+ uzWD81Q8uXGNS8yD6dDynt/lseBjyp2nfC3uQ5fY18VdIcu0MJ9pezBUKrNuhlsy
15
+ XXEZ2DXj4s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P1XMEVbu
48
+ 0RB/0IE36XTMfZ+u9+TRjkBLpmUaX1FdIQQWfwUou/LfaXotoQlhSGAcprLrncuJ
49
+ T44UATYEgO/q9pMM33bdE3eBYZHoT9mSvqoLCN4s0LuwOYItIxLKUj0GulL0VQOI
50
+ SZi+0A1c8cVDXgApkBrWPDQIR9JS4de0gW4hnDoUvHtUc2TYPRnz6N9MtFY=
51
+ -----END RSA PRIVATE KEY-----
@@ -0,0 +1,126 @@
1
+ # $Id$
2
+ #
3
+ #----------------------------------------------------------------------------
4
+ #
5
+ # Copyright (C) 2006-07 by Francis Cianfrocca. All Rights Reserved.
6
+ # Gmail: blackhedd
7
+ #
8
+ # This program is free software; you can redistribute it and/or modify
9
+ # it under the terms of either: 1) the GNU General Public License
10
+ # as published by the Free Software Foundation; either version 2 of the
11
+ # License, or (at your option) any later version; or 2) Ruby's License.
12
+ #
13
+ # See the file COPYING for complete licensing information.
14
+ #
15
+ #---------------------------------------------------------------------------
16
+ #
17
+
18
+ $:.unshift "../lib"
19
+ require 'eventmachine'
20
+ require 'socket'
21
+ require 'test/unit'
22
+
23
+
24
+ class TestAttach < Test::Unit::TestCase
25
+
26
+ Host = "127.0.0.1"
27
+ Port = 9550
28
+
29
+ class EchoServer < EM::Connection
30
+ def receive_data data
31
+ send_data data
32
+ end
33
+ end
34
+
35
+ class EchoClient < EM::Connection
36
+ def initialize
37
+ self.notify_readable = true
38
+ $sock.write("abc\n")
39
+ end
40
+
41
+ def notify_readable
42
+ $read = $sock.readline
43
+ $fd = detach
44
+ end
45
+
46
+ def unbind
47
+ EM.next_tick do
48
+ $sock.write("def\n")
49
+ EM.add_timer(0.5){ EM.stop }
50
+ end
51
+ end
52
+ end
53
+
54
+ def test_attach
55
+ EM.run{
56
+ EM.start_server Host, Port, EchoServer
57
+ $sock = TCPSocket.new Host, Port
58
+ EM.watch $sock, EchoClient
59
+ }
60
+
61
+ assert_equal $read, "abc\n"
62
+ unless defined? JRuby # jruby filenos are not real
63
+ assert_equal $fd, $sock.fileno
64
+ end
65
+ assert_equal false, $sock.closed?
66
+ assert_equal $sock.readline, "def\n"
67
+ end
68
+
69
+ module PipeWatch
70
+ def notify_readable
71
+ $read = $r.readline
72
+ EM.stop
73
+ end
74
+ end
75
+
76
+ def test_attach_pipe
77
+ EM.run{
78
+ $r, $w = IO.pipe
79
+ EM.watch $r, PipeWatch do |c|
80
+ c.notify_readable = true
81
+ end
82
+ $w.write("ghi\n")
83
+ }
84
+
85
+ assert_equal $read, "ghi\n"
86
+ end
87
+
88
+ def test_set_readable
89
+ EM.run{
90
+ $r, $w = IO.pipe
91
+ c = EM.watch $r, PipeWatch do |c|
92
+ c.notify_readable = false
93
+ end
94
+
95
+ EM.next_tick{
96
+ $before = c.notify_readable?
97
+ c.notify_readable = true
98
+ $after = c.notify_readable?
99
+ }
100
+
101
+ $w.write("jkl\n")
102
+ }
103
+
104
+ assert !$before
105
+ assert $after
106
+ assert_equal $read, "jkl\n"
107
+ end
108
+
109
+ module PipeReader
110
+ def receive_data data
111
+ $read = data
112
+ EM.stop
113
+ end
114
+ end
115
+
116
+ def test_read_write_pipe
117
+ EM.run{
118
+ $r, $w = IO.pipe
119
+ EM.attach $r, PipeReader
120
+ writer = EM.attach($w)
121
+ writer.send_data 'ghi'
122
+ }
123
+
124
+ assert_equal $read, "ghi"
125
+ end
126
+ end
@@ -0,0 +1,284 @@
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 'socket'
30
+ require 'test/unit'
31
+
32
+ class TestBasic < Test::Unit::TestCase
33
+
34
+ def setup
35
+ assert(!EM.reactor_running?)
36
+ end
37
+
38
+ def teardown
39
+ assert(!EM.reactor_running?)
40
+ end
41
+
42
+ #-------------------------------------
43
+
44
+ def test_libtype
45
+ lt = EventMachine.library_type
46
+ em_lib = (ENV["EVENTMACHINE_LIBRARY"] || $eventmachine_library || :xxx).to_sym
47
+
48
+ # Running from test runner, under jruby.
49
+ if RUBY_PLATFORM == 'java'
50
+ unless em_lib == :pure_ruby
51
+ assert_equal( :java, lt )
52
+ return
53
+ end
54
+ end
55
+
56
+ case em_lib
57
+ when :pure_ruby
58
+ assert_equal( :pure_ruby, lt )
59
+ when :extension
60
+ assert_equal( :extension, lt )
61
+ when :java
62
+ assert_equal( :java, lt )
63
+ else
64
+ # Running from jruby as a standalone test.
65
+ if RUBY_PLATFORM == 'java'
66
+ assert_equal( :java, lt )
67
+ else
68
+ assert_equal( :extension, lt )
69
+ end
70
+ end
71
+ end
72
+
73
+ #-------------------------------------
74
+
75
+
76
+ def test_em
77
+ EventMachine.run {
78
+ EventMachine.add_timer 0 do
79
+ EventMachine.stop
80
+ end
81
+ }
82
+ end
83
+
84
+ #-------------------------------------
85
+
86
+ def test_timer
87
+ n = 0
88
+ EventMachine.run {
89
+ EventMachine.add_periodic_timer(0.1) {
90
+ n += 1
91
+ EventMachine.stop if n == 2
92
+ }
93
+ }
94
+ end
95
+
96
+ #-------------------------------------
97
+
98
+ # This test once threw an already-running exception.
99
+ module Trivial
100
+ def post_init
101
+ EventMachine.stop
102
+ end
103
+ end
104
+
105
+ def test_server
106
+ EventMachine.run {
107
+ EventMachine.start_server "localhost", 9000, Trivial
108
+ EventMachine.connect "localhost", 9000
109
+ }
110
+ assert( true ) # make sure it halts
111
+ end
112
+
113
+ #--------------------------------------
114
+
115
+ # EventMachine#run_block starts the reactor loop, runs the supplied block, and then STOPS
116
+ # the loop automatically. Contrast with EventMachine#run, which keeps running the reactor
117
+ # even after the supplied block completes.
118
+ def test_run_block
119
+ assert !EM.reactor_running?
120
+ a = nil
121
+ EM.run_block { a = "Worked" }
122
+ assert a
123
+ assert !EM.reactor_running?
124
+ end
125
+
126
+
127
+ #--------------------------------------
128
+
129
+ # TODO! This is an unfinished edge case.
130
+ # EM mishandles uncaught Ruby exceptions that fire from within #unbind handlers.
131
+ # A uncaught Ruby exception results in a call to EM::release_machine (which is in an ensure
132
+ # block in EM::run). But if EM is processing an unbind request, the release_machine call
133
+ # will cause a segmentation fault.
134
+ #
135
+
136
+ TestHost = "127.0.0.1"
137
+ TestPort = 9070
138
+
139
+ class UnbindError < EM::Connection
140
+ def initialize *args
141
+ super
142
+ end
143
+ def connection_completed
144
+ close_connection_after_writing
145
+ end
146
+ def unbind
147
+ raise "Blooey"
148
+ end
149
+ end
150
+
151
+ def xxx_test_unbind_error
152
+ assert_raises( RuntimeError ) {
153
+ EM.run {
154
+ EM.start_server TestHost, TestPort
155
+ EM.connect TestHost, TestPort, UnbindError
156
+ }
157
+ }
158
+ end
159
+
160
+ #------------------------------------
161
+ #
162
+ # TODO. This is an unfinished bug fix.
163
+ # This case was originally reported by Dan Aquino. If you throw a Ruby exception
164
+ # in a post_init handler, it gets rethrown as a confusing reactor exception.
165
+ # The problem is in eventmachine.rb, which calls post_init within the private
166
+ # initialize method of the EM::Connection class. This happens in both the EM::connect
167
+ # method and in the code that responds to connection-accepted events.
168
+ # What happens is that we instantiate the new connection object, which calls
169
+ # initialize, and then after initialize returns, we stick the new connection object
170
+ # into EM's @conns hashtable.
171
+ # But the problem is that Connection::initialize calls #post_init before it returns,
172
+ # and this may be user-written code that may throw an uncaught Ruby exception.
173
+ # If that happens, the reactor will abort, and it will then try to run down open
174
+ # connections. Because @conns never got a chance to properly reflect the new connection
175
+ # (because initialize never returned), we throw a ConnectionNotBound error
176
+ # (eventmachine.rb line 1080).
177
+ # When the bug is fixed, activate this test case.
178
+ #
179
+
180
+ class PostInitError < EM::Connection
181
+ def post_init
182
+ aaa bbb # should produce a Ruby exception
183
+ end
184
+ end
185
+ # This test causes issues, the machine becomes unreleasable after
186
+ # release_machine suffers an exception in event_callback.
187
+ def xxx_test_post_init_error
188
+ assert_raises( EventMachine::ConnectionNotBound ) {
189
+ EM.run {
190
+ EM::Timer.new(1) {EM.stop}
191
+ EM.start_server TestHost, TestPort
192
+ EM.connect TestHost, TestPort, PostInitError
193
+ }
194
+ }
195
+ EM.run {
196
+ EM.stop
197
+ }
198
+ assert !EM.reactor_running?
199
+ end
200
+
201
+ module BrsTestSrv
202
+ def receive_data data
203
+ $received << data
204
+ end
205
+ def unbind
206
+ EM.stop
207
+ end
208
+ end
209
+ module BrsTestCli
210
+ def post_init
211
+ send_data $sent
212
+ close_connection_after_writing
213
+ end
214
+ end
215
+
216
+ # From ticket #50
217
+ def test_byte_range_send
218
+ $received = ''
219
+ $sent = (0..255).to_a.pack('C*')
220
+ EM::run {
221
+ EM::start_server TestHost, TestPort, BrsTestSrv
222
+ EM::connect TestHost, TestPort, BrsTestCli
223
+
224
+ EM::add_timer(0.5) { assert(false, 'test timed out'); EM.stop; Kernel.warn "test timed out!" }
225
+ }
226
+ assert_equal($sent, $received)
227
+ end
228
+
229
+ def test_bind_connect
230
+ local_ip = UDPSocket.open {|s| s.connect('google.com', 80); s.addr.last }
231
+
232
+ bind_port = rand(33333)+1025
233
+
234
+ test = self
235
+ EM.run do
236
+ EM.start_server(TestHost, TestPort, Module.new do
237
+ define_method :post_init do
238
+ begin
239
+ test.assert_equal bind_port, Socket.unpack_sockaddr_in(get_peername).first
240
+ test.assert_equal local_ip, Socket.unpack_sockaddr_in(get_peername).last
241
+ ensure
242
+ EM.stop_event_loop
243
+ end
244
+ end
245
+ end)
246
+ EM.bind_connect local_ip, bind_port, TestHost, TestPort
247
+ end
248
+ end
249
+
250
+ def test_reactor_thread?
251
+ assert !EM.reactor_thread?
252
+ EM.run { assert EM.reactor_thread?; EM.stop }
253
+ assert !EM.reactor_thread?
254
+ end
255
+
256
+ def test_schedule_on_reactor_thread
257
+ x = false
258
+ EM.run do
259
+ EM.schedule { x = true }
260
+ EM.stop
261
+ end
262
+ assert x
263
+ end
264
+
265
+ def test_schedule_from_thread
266
+ x = false
267
+ assert !x
268
+ EM.run do
269
+ Thread.new { EM.schedule { x = true; EM.stop } }.join
270
+ end
271
+ assert x
272
+ end
273
+
274
+ def test_set_heartbeat_interval
275
+ interval = 0.5
276
+ EM.run {
277
+ EM.set_heartbeat_interval interval
278
+ $interval = EM.get_heartbeat_interval
279
+ EM.stop
280
+ }
281
+ assert_equal(interval, $interval)
282
+ end
283
+ end
284
+
@@ -0,0 +1,63 @@
1
+ $:.unshift "../lib"
2
+ require 'eventmachine'
3
+ require 'test/unit'
4
+
5
+ class TestEventMachineChannel < Test::Unit::TestCase
6
+ def test_channel_subscribe
7
+ s = 0
8
+ EM.run do
9
+ c = EM::Channel.new
10
+ c.subscribe { |v| s = v; EM.stop }
11
+ c << 1
12
+ end
13
+ assert_equal 1, s
14
+ end
15
+
16
+ def test_channel_unsubscribe
17
+ s = 0
18
+ EM.run do
19
+ c = EM::Channel.new
20
+ subscription = c.subscribe { |v| s = v }
21
+ c.unsubscribe(subscription)
22
+ c << 1
23
+ EM.next_tick { EM.stop }
24
+ end
25
+ assert_not_equal 1, s
26
+ end
27
+
28
+ def test_channel_pop
29
+ s = 0
30
+ EM.run do
31
+ c = EM::Channel.new
32
+ c.pop{ |v| s = v }
33
+ c << 1
34
+ c << 2
35
+ EM.next_tick { EM.stop }
36
+ end
37
+ assert_equal 1, s
38
+ end
39
+
40
+ def test_channel_reactor_thread_push
41
+ out = []
42
+ c = EM::Channel.new
43
+ c.subscribe { |v| out << v }
44
+ Thread.new { c.push(1,2,3) }.join
45
+ assert out.empty?
46
+
47
+ EM.run { EM.next_tick { EM.stop } }
48
+
49
+ assert_equal [1,2,3], out
50
+ end
51
+
52
+ def test_channel_reactor_thread_callback
53
+ out = []
54
+ c = EM::Channel.new
55
+ Thread.new { c.subscribe { |v| out << v } }.join
56
+ c.push(1,2,3)
57
+ assert out.empty?
58
+
59
+ EM.run { EM.next_tick { EM.stop } }
60
+
61
+ assert_equal [1,2,3], out
62
+ end
63
+ end
@@ -0,0 +1,35 @@
1
+ $:.unshift "../lib"
2
+ require 'eventmachine'
3
+ require 'test/unit'
4
+
5
+ class TestConnectionCount < Test::Unit::TestCase
6
+ def test_idle_connection_count
7
+ EM.run {
8
+ $count = EM.connection_count
9
+ EM.stop_event_loop
10
+ }
11
+
12
+ assert_equal(0, $count)
13
+ end
14
+
15
+ module Client
16
+ def connection_completed
17
+ $client_conns += 1
18
+ EM.stop if $client_conns == 3
19
+ end
20
+ end
21
+
22
+ def test_with_some_connections
23
+ EM.run {
24
+ $client_conns = 0
25
+ $initial_conns = EM.connection_count
26
+ EM.start_server("127.0.0.1", 9999)
27
+ $server_conns = EM.connection_count
28
+ 3.times { EM.connect("127.0.0.1", 9999, Client) }
29
+ }
30
+
31
+ assert_equal(0, $initial_conns)
32
+ assert_equal(1, $server_conns)
33
+ assert_equal(4, $client_conns + $server_conns)
34
+ end
35
+ end