eventmachine-mkroman 1.3.0.dev.1

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 (182) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +179 -0
  3. data/GNU +281 -0
  4. data/LICENSE +60 -0
  5. data/README.md +110 -0
  6. data/docs/DocumentationGuidesIndex.md +27 -0
  7. data/docs/GettingStarted.md +520 -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 +52 -0
  35. data/ext/cmain.cpp +1046 -0
  36. data/ext/ed.cpp +2243 -0
  37. data/ext/ed.h +463 -0
  38. data/ext/em.cpp +2378 -0
  39. data/ext/em.h +266 -0
  40. data/ext/eventmachine.h +152 -0
  41. data/ext/extconf.rb +291 -0
  42. data/ext/fastfilereader/extconf.rb +120 -0
  43. data/ext/fastfilereader/mapper.cpp +214 -0
  44. data/ext/fastfilereader/mapper.h +59 -0
  45. data/ext/fastfilereader/rubymain.cpp +126 -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 +174 -0
  51. data/ext/rubymain.cpp +1643 -0
  52. data/ext/ssl.cpp +701 -0
  53. data/ext/ssl.h +103 -0
  54. data/ext/wait_for_single_fd.h +36 -0
  55. data/java/.classpath +8 -0
  56. data/java/.project +17 -0
  57. data/java/src/com/rubyeventmachine/EmReactor.java +625 -0
  58. data/java/src/com/rubyeventmachine/EmReactorException.java +40 -0
  59. data/java/src/com/rubyeventmachine/EmReactorInterface.java +70 -0
  60. data/java/src/com/rubyeventmachine/EventableChannel.java +72 -0
  61. data/java/src/com/rubyeventmachine/EventableDatagramChannel.java +201 -0
  62. data/java/src/com/rubyeventmachine/EventableSocketChannel.java +415 -0
  63. data/java/src/com/rubyeventmachine/NullEmReactor.java +157 -0
  64. data/java/src/com/rubyeventmachine/NullEventableChannel.java +81 -0
  65. data/lib/em/buftok.rb +59 -0
  66. data/lib/em/callback.rb +58 -0
  67. data/lib/em/channel.rb +69 -0
  68. data/lib/em/completion.rb +307 -0
  69. data/lib/em/connection.rb +802 -0
  70. data/lib/em/deferrable/pool.rb +2 -0
  71. data/lib/em/deferrable.rb +210 -0
  72. data/lib/em/file_watch.rb +73 -0
  73. data/lib/em/future.rb +61 -0
  74. data/lib/em/io_streamer.rb +68 -0
  75. data/lib/em/iterator.rb +252 -0
  76. data/lib/em/messages.rb +66 -0
  77. data/lib/em/pool.rb +151 -0
  78. data/lib/em/process_watch.rb +45 -0
  79. data/lib/em/processes.rb +123 -0
  80. data/lib/em/protocols/header_and_content.rb +138 -0
  81. data/lib/em/protocols/httpclient.rb +303 -0
  82. data/lib/em/protocols/httpclient2.rb +602 -0
  83. data/lib/em/protocols/line_and_text.rb +125 -0
  84. data/lib/em/protocols/line_protocol.rb +33 -0
  85. data/lib/em/protocols/linetext2.rb +179 -0
  86. data/lib/em/protocols/memcache.rb +331 -0
  87. data/lib/em/protocols/object_protocol.rb +46 -0
  88. data/lib/em/protocols/postgres3.rb +246 -0
  89. data/lib/em/protocols/saslauth.rb +175 -0
  90. data/lib/em/protocols/smtpclient.rb +394 -0
  91. data/lib/em/protocols/smtpserver.rb +666 -0
  92. data/lib/em/protocols/socks4.rb +66 -0
  93. data/lib/em/protocols/stomp.rb +205 -0
  94. data/lib/em/protocols/tcptest.rb +54 -0
  95. data/lib/em/protocols.rb +37 -0
  96. data/lib/em/pure_ruby.rb +1300 -0
  97. data/lib/em/queue.rb +80 -0
  98. data/lib/em/resolver.rb +232 -0
  99. data/lib/em/spawnable.rb +84 -0
  100. data/lib/em/streamer.rb +118 -0
  101. data/lib/em/threaded_resource.rb +90 -0
  102. data/lib/em/tick_loop.rb +85 -0
  103. data/lib/em/timers.rb +61 -0
  104. data/lib/em/version.rb +3 -0
  105. data/lib/eventmachine.rb +1602 -0
  106. data/lib/jeventmachine.rb +319 -0
  107. data/rakelib/package.rake +120 -0
  108. data/rakelib/test.rake +6 -0
  109. data/rakelib/test_pure.rake +11 -0
  110. data/tests/client.crt +31 -0
  111. data/tests/client.key +51 -0
  112. data/tests/dhparam.pem +13 -0
  113. data/tests/em_ssl_handlers.rb +165 -0
  114. data/tests/em_test_helper.rb +198 -0
  115. data/tests/encoded_client.key +54 -0
  116. data/tests/jruby/test_jeventmachine.rb +38 -0
  117. data/tests/test_attach.rb +199 -0
  118. data/tests/test_basic.rb +321 -0
  119. data/tests/test_channel.rb +75 -0
  120. data/tests/test_completion.rb +178 -0
  121. data/tests/test_connection_count.rb +83 -0
  122. data/tests/test_connection_write.rb +35 -0
  123. data/tests/test_defer.rb +35 -0
  124. data/tests/test_deferrable.rb +35 -0
  125. data/tests/test_epoll.rb +141 -0
  126. data/tests/test_error_handler.rb +38 -0
  127. data/tests/test_exc.rb +37 -0
  128. data/tests/test_file_watch.rb +86 -0
  129. data/tests/test_fork.rb +75 -0
  130. data/tests/test_futures.rb +170 -0
  131. data/tests/test_handler_check.rb +35 -0
  132. data/tests/test_hc.rb +155 -0
  133. data/tests/test_httpclient.rb +238 -0
  134. data/tests/test_httpclient2.rb +132 -0
  135. data/tests/test_idle_connection.rb +31 -0
  136. data/tests/test_inactivity_timeout.rb +102 -0
  137. data/tests/test_io_streamer.rb +48 -0
  138. data/tests/test_ipv4.rb +96 -0
  139. data/tests/test_ipv6.rb +107 -0
  140. data/tests/test_iterator.rb +122 -0
  141. data/tests/test_kb.rb +28 -0
  142. data/tests/test_keepalive.rb +113 -0
  143. data/tests/test_line_protocol.rb +33 -0
  144. data/tests/test_ltp.rb +155 -0
  145. data/tests/test_ltp2.rb +332 -0
  146. data/tests/test_many_fds.rb +21 -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 +109 -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 +147 -0
  154. data/tests/test_proxy_connection.rb +180 -0
  155. data/tests/test_pure.rb +156 -0
  156. data/tests/test_queue.rb +64 -0
  157. data/tests/test_resolver.rb +129 -0
  158. data/tests/test_running.rb +14 -0
  159. data/tests/test_sasl.rb +46 -0
  160. data/tests/test_send_file.rb +217 -0
  161. data/tests/test_servers.rb +32 -0
  162. data/tests/test_shutdown_hooks.rb +23 -0
  163. data/tests/test_smtpclient.rb +75 -0
  164. data/tests/test_smtpserver.rb +90 -0
  165. data/tests/test_sock_opt.rb +53 -0
  166. data/tests/test_spawn.rb +290 -0
  167. data/tests/test_ssl_args.rb +70 -0
  168. data/tests/test_ssl_dhparam.rb +57 -0
  169. data/tests/test_ssl_ecdh_curve.rb +57 -0
  170. data/tests/test_ssl_extensions.rb +24 -0
  171. data/tests/test_ssl_inline_cert.rb +222 -0
  172. data/tests/test_ssl_methods.rb +31 -0
  173. data/tests/test_ssl_protocols.rb +190 -0
  174. data/tests/test_ssl_verify.rb +108 -0
  175. data/tests/test_stomp.rb +38 -0
  176. data/tests/test_system.rb +46 -0
  177. data/tests/test_threaded_resource.rb +68 -0
  178. data/tests/test_tick_loop.rb +58 -0
  179. data/tests/test_timers.rb +150 -0
  180. data/tests/test_ud.rb +8 -0
  181. data/tests/test_unbind_reason.rb +40 -0
  182. metadata +389 -0
@@ -0,0 +1,165 @@
1
+ # frozen_string_literal: true
2
+
3
+ ##
4
+ # EMSSLHandlers has two classes, `Client` and `Server`, and one method,
5
+ # `client_server`, which is a wrapper around
6
+ #
7
+ # EM.run do
8
+ # EM.start_server IP, PORT, s_hndlr, server
9
+ # EM.connect IP, PORT, c_hndlr, client
10
+ # end
11
+ #
12
+ # It also passes parameters to the `start_tls` call within the `post_init`
13
+ # callbacks of Client and Server.
14
+ #
15
+ # Client and Server have most standard callbacks and many 'get_*' function values
16
+ # as attributes.
17
+ #
18
+ # `Client` has a `:client_unbind` parameter, which when set to true, calls
19
+ # `EM.stop_event_loop` in the `unbind` callback.
20
+ #
21
+ # `Server` has two additional parameters.
22
+ #
23
+ # `:ssl_verify_result`, which is normally set to true/false for the
24
+ # `ssl_verify_peer` return value. If it is set to a String starting with "|RAISE|",
25
+ # the remaing string will be raised.
26
+ #
27
+ # `:stop_after_handshake`, when set to true, will close the connection and then
28
+ # call `EM.stop_event_loop`.
29
+ #
30
+ module EMSSLHandlers
31
+
32
+ IP, PORT = "127.0.0.1", 16784
33
+
34
+ # is OpenSSL version >= 1.1.0
35
+ IS_SSL_GE_1_1 = (EM::OPENSSL_LIBRARY_VERSION[/OpenSSL (\d+\.\d+\.\d+)/, 1]
36
+ .split('.').map(&:to_i) <=> [1,1]) == 1
37
+
38
+ # common start_tls parameters
39
+ SSL_3 = { ssl_version: %w(SSLv3) }
40
+ TLS_1_2 = { ssl_version: %w(TLSv1_2) }
41
+ TLS_1_3 = { ssl_version: %w(TLSv1_3) }
42
+ TLS_ALL = { ssl_version: Test::Unit::TestCase::SSL_AVAIL }
43
+
44
+ module Client
45
+ def initialize(tls = nil)
46
+ @@tls = tls ? tls.dup : tls
47
+ @@handshake_completed = false
48
+ @@cert = nil
49
+ @@cert_value = nil
50
+ @@cipher_bits = nil
51
+ @@cipher_name = nil
52
+ @@cipher_protocol = nil
53
+ @@ssl_verify_result = @@tls ? @@tls.delete(:ssl_verify_result) : nil
54
+ @@client_unbind = @@tls ? @@tls.delete(:client_unbind) : nil
55
+ end
56
+
57
+ def self.cert ; @@cert end
58
+ def self.cert_value ; @@cert_value end
59
+ def self.cipher_bits ; @@cipher_bits end
60
+ def self.cipher_name ; @@cipher_name end
61
+ def self.cipher_protocol ; @@cipher_protocol end
62
+ def self.handshake_completed? ; !!@@handshake_completed end
63
+
64
+ def post_init
65
+ if @@tls
66
+ start_tls @@tls
67
+ else
68
+ start_tls
69
+ end
70
+ end
71
+
72
+ def ssl_verify_peer(cert)
73
+ @@cert = cert
74
+ if @@ssl_verify_result.is_a?(String) && @@ssl_verify_result.start_with?("|RAISE|")
75
+ raise @@ssl_verify_result.sub('|RAISE|', '')
76
+ else
77
+ @@ssl_verify_result
78
+ end
79
+ end
80
+
81
+ def ssl_handshake_completed
82
+ @@handshake_completed = true
83
+ @@cert_value = get_peer_cert
84
+ @@cipher_bits = get_cipher_bits
85
+ @@cipher_name = get_cipher_name
86
+ @@cipher_protocol = get_cipher_protocol
87
+
88
+ if "TLSv1.3" != @@cipher_protocol
89
+ close_connection
90
+ EM.stop_event_loop
91
+ end
92
+ end
93
+
94
+ def unbind
95
+ EM.stop_event_loop if @@client_unbind
96
+ end
97
+ end
98
+
99
+ module Server
100
+ def initialize(tls = nil)
101
+ @@tls = tls ? tls.dup : tls
102
+ @@handshake_completed = false
103
+ @@cert_value = nil
104
+ @@cipher_bits = nil
105
+ @@cipher_name = nil
106
+ @@cipher_protocol = nil
107
+ @@sni_hostname = "not set"
108
+ @@ssl_verify_result = @@tls ? @@tls.delete(:ssl_verify_result) : nil
109
+ @@stop_after_handshake = @@tls ? @@tls.delete(:stop_after_handshake) : nil
110
+ end
111
+
112
+ def self.cert ; @@cert end
113
+ def self.cert_value ; @@cert_value end
114
+ def self.cipher_bits ; @@cipher_bits end
115
+ def self.cipher_name ; @@cipher_name end
116
+ def self.cipher_protocol ; @@cipher_protocol end
117
+ def self.handshake_completed? ; !!@@handshake_completed end
118
+ def self.sni_hostname ; @@sni_hostname end
119
+
120
+ def post_init
121
+ if @@tls
122
+ start_tls @@tls
123
+ else
124
+ start_tls
125
+ end
126
+ end
127
+
128
+ def ssl_verify_peer(cert)
129
+ @@cert = cert
130
+ if @@ssl_verify_result.is_a?(String) && @@ssl_verify_result.start_with?("|RAISE|")
131
+ raise @@ssl_verify_result.sub('|RAISE|', '')
132
+ else
133
+ @@ssl_verify_result
134
+ end
135
+ end
136
+
137
+ def ssl_handshake_completed
138
+ @@handshake_completed = true
139
+ @@cert_value = get_peer_cert
140
+ @@cipher_bits = get_cipher_bits
141
+ @@cipher_name = get_cipher_name
142
+ @@cipher_protocol = get_cipher_protocol
143
+
144
+ @@sni_hostname = get_sni_hostname
145
+ if ("TLSv1.3" == @@cipher_protocol) || @@stop_after_handshake
146
+ close_connection
147
+ EM.stop_event_loop
148
+ end
149
+ end
150
+
151
+ def unbind
152
+ EM.stop_event_loop unless @@handshake_completed
153
+ end
154
+ end
155
+
156
+ def client_server(c_hndlr = Client, s_hndlr = Server,
157
+ client: nil, server: nil, timeout: 3.0)
158
+ EM.run do
159
+ # fail safe stop
160
+ setup_timeout timeout
161
+ EM.start_server IP, PORT, s_hndlr, server
162
+ EM.connect IP, PORT, c_hndlr, client
163
+ end
164
+ end
165
+ end if EM.ssl?
@@ -0,0 +1,198 @@
1
+ require 'em/pure_ruby' if ENV['EM_PURE_RUBY']
2
+ require 'eventmachine'
3
+ require 'rbconfig'
4
+ require 'socket'
5
+
6
+ # verbose fun is to stop warnings when loading test-unit 3.2.9 in trunk
7
+ verbose, $VERBOSE = $VERBOSE, nil
8
+ require 'test/unit'
9
+ $VERBOSE = verbose
10
+
11
+ class Test::Unit::TestCase
12
+
13
+ # below outputs to console on load
14
+ # SSL_AVAIL is used by SSL tests
15
+ puts "", RUBY_DESCRIPTION
16
+ puts "\nEM.library_type #{EM.library_type.to_s.ljust(16)} EM.ssl? #{EM.ssl?}"
17
+ if EM.ssl?
18
+ require 'openssl'
19
+ ssl_lib_vers = OpenSSL.const_defined?(:OPENSSL_LIBRARY_VERSION) ?
20
+ OpenSSL::OPENSSL_LIBRARY_VERSION : 'na'
21
+ puts "OpenSSL OPENSSL_LIBRARY_VERSION: #{ssl_lib_vers}\n" \
22
+ " OPENSSL_VERSION: #{OpenSSL::OPENSSL_VERSION}\n" \
23
+ " EM OPENSSL_LIBRARY_VERSION: #{EM::OPENSSL_LIBRARY_VERSION}\n" \
24
+ " OPENSSL_VERSION: #{EM::OPENSSL_VERSION}"
25
+
26
+ # assumes all 2.x versions include support for TLSv1_2
27
+ temp = []
28
+ temp << 'SSLv2' unless EM::OPENSSL_NO_SSL2
29
+ temp << 'SSLv3' unless EM::OPENSSL_NO_SSL3
30
+ temp += %w[TLSv1 TLSv1_1 TLSv1_2]
31
+ temp << 'TLSv1_3' if EM.const_defined? :EM_PROTO_TLSv1_3
32
+ temp.sort!
33
+ puts " SSL_AVAIL: #{temp.join(' ')}", ""
34
+ SSL_AVAIL = temp.freeze
35
+ else
36
+ puts "\nEventMachine is not built with OpenSSL support, skipping tests in",
37
+ "files tests/test_ssl_*.rb"
38
+ end
39
+
40
+ class EMTestTimeout < StandardError ; end
41
+
42
+ def setup_timeout(timeout = TIMEOUT_INTERVAL)
43
+ EM.schedule {
44
+ EM.add_timer(timeout) {
45
+ raise EMTestTimeout, "Test was cancelled after #{timeout} seconds."
46
+ }
47
+ }
48
+ end
49
+
50
+ def port_in_use?(port, host="127.0.0.1")
51
+ s = TCPSocket.new(host, port)
52
+ s.close
53
+ s
54
+ rescue Errno::ECONNREFUSED
55
+ false
56
+ end
57
+
58
+ def next_port
59
+ @@port ||= 9000
60
+ begin
61
+ @@port += 1
62
+ end while port_in_use?(@@port)
63
+
64
+ @@port
65
+ end
66
+
67
+ # Returns true if the host have a localhost 127.0.0.1 IPv4.
68
+ def self.local_ipv4?
69
+ return @@has_local_ipv4 if defined?(@@has_local_ipv4)
70
+ begin
71
+ get_my_ipv4_address "127.0.0.1"
72
+ @@has_local_ipv4 = true
73
+ rescue
74
+ @@has_local_ipv4 = false
75
+ end
76
+ end
77
+
78
+ # Returns true if the host have a public IPv4 and stores it in
79
+ # @@public_ipv4.
80
+ def self.public_ipv4?
81
+ return @@has_public_ipv4 if defined?(@@has_public_ipv4)
82
+ begin
83
+ @@public_ipv4 = get_my_ipv4_address "1.2.3.4"
84
+ @@has_public_ipv4 = true
85
+ rescue
86
+ @@has_public_ipv4 = false
87
+ end
88
+ end
89
+
90
+ # Returns true if the host have a localhost ::1 IPv6.
91
+ def self.local_ipv6?
92
+ return @@has_local_ipv6 if defined?(@@has_local_ipv6)
93
+ begin
94
+ get_my_ipv6_address "::1"
95
+ @@has_local_ipv6 = true
96
+ rescue
97
+ @@has_local_ipv6 = false
98
+ end
99
+ end
100
+
101
+ # Returns true if the host have a public IPv6 and stores it in
102
+ # @@public_ipv6.
103
+ def self.public_ipv6?
104
+ return @@has_public_ipv6 if defined?(@@has_public_ipv6)
105
+ begin
106
+ @@public_ipv6 = get_my_ipv6_address "2001::1"
107
+ @@has_public_ipv6 = true
108
+ rescue
109
+ @@has_public_ipv6 = false
110
+ end
111
+ end
112
+
113
+ # Returns an array with the localhost addresses (IPv4 and/or IPv6).
114
+ def local_ips
115
+ return @@local_ips if defined?(@@local_ips)
116
+ @@local_ips = []
117
+ @@local_ips << "127.0.0.1" if self.class.local_ipv4?
118
+ @@local_ips << "::1" if self.class.local_ipv6?
119
+ @@local_ips
120
+ end
121
+
122
+ def exception_class
123
+ jruby? ? NativeException : RuntimeError
124
+ end
125
+
126
+ module PlatformHelper
127
+ # http://blog.emptyway.com/2009/11/03/proper-way-to-detect-windows-platform-in-ruby/
128
+ def windows?
129
+ RbConfig::CONFIG['host_os'] =~ /mswin|mingw/
130
+ end
131
+
132
+ def darwin?
133
+ RUBY_PLATFORM =~ /darwin/
134
+ end
135
+
136
+ def solaris?
137
+ RUBY_PLATFORM =~ /solaris/
138
+ end
139
+
140
+ # http://stackoverflow.com/questions/1342535/how-can-i-tell-if-im-running-from-jruby-vs-ruby/1685970#1685970
141
+ def jruby?
142
+ defined? JRUBY_VERSION
143
+ end
144
+
145
+ def rbx?
146
+ defined?(RUBY_ENGINE) && RUBY_ENGINE == 'rbx'
147
+ end
148
+ end
149
+
150
+ include PlatformHelper
151
+ extend PlatformHelper
152
+
153
+ # Tests may run slower on windows or Appveyor. YMMV
154
+ TIMEOUT_INTERVAL = windows? ? 0.25 : 0.25
155
+
156
+ module EMTestCasePrepend
157
+ def setup
158
+ EM.stop while EM.reactor_running?
159
+ end
160
+
161
+ def teardown
162
+ EM.cleanup_machine
163
+ end
164
+ end
165
+ prepend EMTestCasePrepend
166
+
167
+ def silent
168
+ backup, $VERBOSE = $VERBOSE, nil
169
+ begin
170
+ yield
171
+ ensure
172
+ $VERBOSE = backup
173
+ end
174
+ end
175
+
176
+
177
+ private
178
+
179
+ def self.get_my_ipv4_address ip
180
+ orig, Socket.do_not_reverse_lookup = Socket.do_not_reverse_lookup, true # turn off reverse DNS resolution temporarily
181
+ UDPSocket.open(Socket::AF_INET) do |s|
182
+ s.connect ip, 1
183
+ s.addr.last
184
+ end
185
+ ensure
186
+ Socket.do_not_reverse_lookup = orig
187
+ end
188
+
189
+ def self.get_my_ipv6_address ip
190
+ orig, Socket.do_not_reverse_lookup = Socket.do_not_reverse_lookup, true # turn off reverse DNS resolution temporarily
191
+ UDPSocket.open(Socket::AF_INET6) do |s|
192
+ s.connect ip, 1
193
+ s.addr.last
194
+ end
195
+ ensure
196
+ Socket.do_not_reverse_lookup = orig
197
+ end
198
+ end
@@ -0,0 +1,54 @@
1
+ -----BEGIN RSA PRIVATE KEY-----
2
+ Proc-Type: 4,ENCRYPTED
3
+ DEK-Info: AES-128-CBC,4BFAC39AEF67B2BED03FB8D0E34BDB6E
4
+
5
+ KXJGir0Kro0c4qoFCsyCyYQgBS0ul4FinsCei3haYwz3Vd/uvZD8wBoedzVho/Mz
6
+ 99nZXZ52lHuwewGVvBeAnSXTrAtWCV2S9ZivYLZNqsEyxRlUF0SYat31bD2OImh8
7
+ kXNC89HA9CEpRp3Zc0DU9JqqaRMv6SloMZA9AM/ioeHGj2o8Ajf4Vi0jg766cVFc
8
+ CyxHy+IOJww8FSBwGaghBixNS4rhtUonJUDeInB7C0jFqkoHQG1JCSGTzbK66bDf
9
+ kDhvUzxJnKUTezXGl5sKTRznla7aurWY5kFjz0b/api8ZCm/LvvsDipZbwwOHm31
10
+ wMj9LPLzd0Sz2c3TyoPc/oCS9KVFnszndjaT6ydRLvHgF2XpPbL+xJz0HJwsvkis
11
+ kls0NHw69GvzTj6kZfz9a5XLpwjoGpeeMNBHw7SDRUNJnOEFwTecJL3NhCVSVgIy
12
+ owYTWDmPR8rcyNd007uhCio2+VxkZE2Hdmk0drz69mp0CNQbxe0qF8XKHTBT74I/
13
+ L3KQITmMpSDNEn8bY/KmKpB6iuVBURvTpz5ZAPStsp4hcp0LlmPuhZZYGWC4Hox5
14
+ svsp95iE5esN67RNUI3/twZhtJu8e5tIKy6qEWMWdrVeI0oVoLmfK+g5uQJaMu+Z
15
+ M/SLeTHjVOSq7r4Tg5Xmd8nzEQ8EyJKZCJshD7LZxjA34bOLID9Vhz0j/uE4IhNI
16
+ APO6gllYsWAGO4hADZH24i8ZvS2dX4ZR2Yt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AHIn6iB0oIb2oYVzlzthNs
48
+ j+EEIMgZRQzrW1aEf2BTYlwCjRqCYoE0P6fc6RrPMYS+fLmFkjEikrC9mduoWItc
49
+ FtTLD/OY0xhXb5lF9UFFNmQSqMvagfI4GQ9vGg78vatSODw+Js88MqaQa3lbzcP3
50
+ so5Bz2hBMY7bKjppUvseJtZETjSF4pjOVDGdVGpXis1iZj1DkP0IyXgt+u2LkvhQ
51
+ rYtYZHxEUVwjJyEtd0kvXDq5g5jkEO6A9aOMBUU4B4cbrRNVSIfpXPJ7koZpIRwd
52
+ A02+K21gS+DEkE8wBES+Qsuv8lTkTBpSFh60M8snrmJZ/2nJmX0SQ+kMakaCuh0h
53
+ q5orm9wFUiOPOfWJe7JNHJ1pH9Yi+elbQEr4yKc2tuRuLXVNRlMNSWyaEjCUqpi1
54
+ -----END RSA PRIVATE KEY-----
@@ -0,0 +1,38 @@
1
+ if !(RUBY_PLATFORM =~ /java/)
2
+ puts "Ignoring tests in #{__FILE__}. They must be run in JRuby "
3
+ else
4
+ require 'test/unit'
5
+ require 'jeventmachine'
6
+
7
+ class TestJEventmachine < Test::Unit::TestCase
8
+
9
+ def setup
10
+ EventMachine.instance_variable_set("@em", nil)
11
+ load 'jeventmachine.rb'
12
+ end
13
+
14
+ def test_can_make_calls_without_errors_before_initialization
15
+ assert_equal nil, EventMachine.signal_loopbreak
16
+ assert_equal nil, EventMachine.stop_tcp_server(123)
17
+ assert_equal nil, EventMachine.send_data(123, "rewr", 4)
18
+ assert_equal nil, EventMachine.close_connection(332, nil)
19
+ end
20
+
21
+ def test_create
22
+ EventMachine::initialize_event_machine
23
+ em = EventMachine::instance_variable_get("@em")
24
+ assert_equal true, em.is_a?(Java::com.rubyeventmachine.EmReactor)
25
+ end
26
+
27
+ def test_can_make_calls_without_errors_after_release
28
+ EventMachine.initialize_event_machine
29
+ EventMachine.release_machine
30
+
31
+ assert_equal nil, EventMachine.signal_loopbreak
32
+ assert_equal nil, EventMachine.stop_tcp_server(123)
33
+ assert_equal nil, EventMachine.send_data(123, "rewr", 4)
34
+ assert_equal nil, EventMachine.close_connection(332, nil)
35
+ end
36
+
37
+ end
38
+ end
@@ -0,0 +1,199 @@
1
+ require_relative 'em_test_helper'
2
+
3
+ class TestAttach < Test::Unit::TestCase
4
+ class EchoServer < EM::Connection
5
+ def receive_data data
6
+ $received_data << data
7
+ send_data data
8
+ end
9
+ end
10
+
11
+ class EchoClient < EM::Connection
12
+ def initialize socket
13
+ self.notify_readable = true
14
+ @socket = socket
15
+ @socket.write("abc\n")
16
+ end
17
+
18
+ def notify_readable
19
+ $read = @socket.readline
20
+ $fd = detach
21
+ end
22
+
23
+ def unbind
24
+ EM.next_tick do
25
+ @socket.write("def\n")
26
+ EM.add_timer(0.1) { EM.stop }
27
+ end
28
+ end
29
+ end
30
+
31
+ def setup
32
+ @port = next_port
33
+ $read, $r, $w, $fd = nil
34
+ $received_data = ""
35
+ end
36
+
37
+ def teardown
38
+ [$r, $w].each do |io|
39
+ io.close rescue nil
40
+ end
41
+ $received_data = nil
42
+ end
43
+
44
+ def test_attach
45
+ socket = nil
46
+
47
+ EM.run {
48
+ EM.start_server "127.0.0.1", @port, EchoServer
49
+ socket = TCPSocket.new "127.0.0.1", @port
50
+ EM.watch socket, EchoClient, socket
51
+ }
52
+
53
+ assert_equal $read, "abc\n"
54
+ unless jruby? # jruby filenos are not real
55
+ assert_equal $fd, socket.fileno
56
+ end
57
+ assert_equal false, socket.closed?
58
+ assert_equal socket.readline, "def\n"
59
+ end
60
+
61
+ module PipeWatch
62
+ def notify_readable
63
+ $read = $r.readline
64
+ EM.stop
65
+ end
66
+ end
67
+
68
+ def test_attach_server
69
+ omit_if(jruby?)
70
+ $before = TCPServer.new("127.0.0.1", @port)
71
+ sig = nil
72
+ EM.run {
73
+ sig = EM.attach_server $before, EchoServer
74
+
75
+ handler = Class.new(EM::Connection) do
76
+ def initialize
77
+ send_data "hello world"
78
+ close_connection_after_writing
79
+ EM.add_timer(0.1) { EM.stop }
80
+ end
81
+ end
82
+ EM.connect("127.0.0.1", @port, handler)
83
+ }
84
+
85
+ assert_equal false, $before.closed?
86
+ assert_equal "hello world", $received_data
87
+ assert sig.is_a?(Integer)
88
+ end
89
+
90
+ def test_attach_pipe
91
+ EM.run{
92
+ $r, $w = IO.pipe
93
+ EM.watch $r, PipeWatch do |c|
94
+ c.notify_readable = true
95
+ end
96
+ $w.write("ghi\n")
97
+ }
98
+
99
+ assert_equal $read, "ghi\n"
100
+ end
101
+
102
+ def test_set_readable
103
+ before, after = nil
104
+
105
+ EM.run{
106
+ $r, $w = IO.pipe
107
+ c = EM.watch $r, PipeWatch do |con|
108
+ con.notify_readable = false
109
+ end
110
+
111
+ EM.next_tick{
112
+ before = c.notify_readable?
113
+ c.notify_readable = true
114
+ after = c.notify_readable?
115
+ }
116
+
117
+ $w.write("jkl\n")
118
+ }
119
+
120
+ assert !before
121
+ assert after
122
+ assert_equal $read, "jkl\n"
123
+ end
124
+
125
+ def test_read_write_pipe
126
+ result = nil
127
+
128
+ pipe_reader = Module.new do
129
+ define_method :receive_data do |data|
130
+ result = data
131
+ EM.stop
132
+ end
133
+ end
134
+
135
+ r,w = IO.pipe
136
+
137
+ EM.run {
138
+ EM.attach r, pipe_reader
139
+ writer = EM.attach(w)
140
+ writer.send_data 'ghi'
141
+
142
+ # XXX: Process will hang in Windows without this line
143
+ writer.close_connection_after_writing
144
+ }
145
+
146
+ assert_equal "ghi", result
147
+ ensure
148
+ [r,w].each {|io| io.close rescue nil }
149
+ end
150
+
151
+ # This test shows that watch_only? is true for EM.watch
152
+ def test_watch_only
153
+ r, w = IO.pipe
154
+ $watch_only = nil
155
+
156
+ EM.run do
157
+ EM.watch r do |c|
158
+ assert_true(c.watch_only?)
159
+ c.notify_readable = true
160
+ def c.receive_data data
161
+ fail('this method should not be called')
162
+ end
163
+ def c.notify_readable
164
+ $watch_only = watch_only?
165
+ end
166
+ end
167
+ w.write 'hello'
168
+ EM.next_tick { EM.stop }
169
+ end
170
+
171
+ assert_true($watch_only)
172
+ end
173
+
174
+ # This test shows that watch_only? is false for EM.attach
175
+ def test_attach_data
176
+ pend("\nFIXME: Freezes Windows testing as of 2018-07-31") if windows?
177
+ r, w = IO.pipe
178
+ $watch_only = nil
179
+ $read = []
180
+
181
+ EM.run do
182
+ EM.attach r do |c|
183
+ assert_false(c.watch_only?)
184
+ def c.receive_data data
185
+ $watch_only = watch_only?
186
+ $read << data
187
+ end
188
+ def c.notify_readable
189
+ fail('this method should not be called')
190
+ end
191
+ end
192
+ w.write 'world'
193
+ EM.next_tick { EM.stop }
194
+ end
195
+
196
+ assert_false($watch_only)
197
+ assert_equal('world', $read.first)
198
+ end
199
+ end