eventmachine 1.0.3-x86-mingw32 → 1.2.0.dev.2-x86-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 (101) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +84 -1
  3. data/README.md +6 -7
  4. data/ext/binder.cpp +10 -10
  5. data/ext/binder.h +5 -5
  6. data/ext/cmain.cpp +173 -61
  7. data/ext/ed.cpp +262 -127
  8. data/ext/ed.h +50 -30
  9. data/ext/em.cpp +491 -445
  10. data/ext/em.h +101 -36
  11. data/ext/eventmachine.h +67 -51
  12. data/ext/extconf.rb +124 -31
  13. data/ext/fastfilereader/extconf.rb +9 -2
  14. data/ext/fastfilereader/mapper.cpp +3 -1
  15. data/ext/fastfilereader/rubymain.cpp +7 -7
  16. data/ext/kb.cpp +1 -1
  17. data/ext/pipe.cpp +11 -4
  18. data/ext/project.h +26 -6
  19. data/ext/rubymain.cpp +408 -201
  20. data/ext/ssl.cpp +167 -20
  21. data/ext/ssl.h +11 -2
  22. data/java/src/com/rubyeventmachine/EmReactor.java +16 -0
  23. data/java/src/com/rubyeventmachine/EventableChannel.java +2 -0
  24. data/java/src/com/rubyeventmachine/EventableDatagramChannel.java +6 -0
  25. data/java/src/com/rubyeventmachine/EventableSocketChannel.java +55 -10
  26. data/lib/1.9/fastfilereaderext.so +0 -0
  27. data/lib/1.9/rubyeventmachine.so +0 -0
  28. data/lib/2.0/fastfilereaderext.so +0 -0
  29. data/lib/2.0/rubyeventmachine.so +0 -0
  30. data/lib/2.1/fastfilereaderext.so +0 -0
  31. data/lib/2.1/rubyeventmachine.so +0 -0
  32. data/lib/2.2/fastfilereaderext.so +0 -0
  33. data/lib/2.2/rubyeventmachine.so +0 -0
  34. data/lib/2.3/fastfilereaderext.so +0 -0
  35. data/lib/2.3/rubyeventmachine.so +0 -0
  36. data/lib/em/buftok.rb +34 -85
  37. data/lib/em/channel.rb +5 -0
  38. data/lib/em/completion.rb +2 -2
  39. data/lib/em/connection.rb +62 -4
  40. data/lib/em/iterator.rb +30 -48
  41. data/lib/em/pool.rb +1 -1
  42. data/lib/em/protocols/httpclient.rb +31 -11
  43. data/lib/em/protocols/line_and_text.rb +4 -4
  44. data/lib/em/protocols/linetext2.rb +44 -39
  45. data/lib/em/protocols/smtpclient.rb +60 -31
  46. data/lib/em/protocols/smtpserver.rb +32 -9
  47. data/lib/em/pure_ruby.rb +8 -3
  48. data/lib/em/queue.rb +16 -7
  49. data/lib/em/resolver.rb +64 -24
  50. data/lib/em/threaded_resource.rb +2 -2
  51. data/lib/em/tick_loop.rb +19 -19
  52. data/lib/em/version.rb +1 -1
  53. data/lib/eventmachine.rb +96 -49
  54. data/lib/jeventmachine.rb +17 -0
  55. data/rakelib/package.rake +31 -4
  56. data/tests/dhparam.pem +13 -0
  57. data/tests/em_test_helper.rb +87 -0
  58. data/tests/test_attach.rb +25 -0
  59. data/tests/test_basic.rb +27 -38
  60. data/tests/test_channel.rb +14 -1
  61. data/tests/test_completion.rb +1 -0
  62. data/tests/test_connection_count.rb +22 -1
  63. data/tests/test_connection_write.rb +35 -0
  64. data/tests/test_defer.rb +17 -0
  65. data/tests/test_epoll.rb +26 -14
  66. data/tests/test_file_watch.rb +1 -0
  67. data/tests/test_fork.rb +75 -0
  68. data/tests/test_httpclient.rb +43 -0
  69. data/tests/test_idle_connection.rb +6 -4
  70. data/tests/test_ipv4.rb +125 -0
  71. data/tests/test_ipv6.rb +131 -0
  72. data/tests/test_iterator.rb +115 -0
  73. data/tests/test_kb.rb +19 -25
  74. data/tests/test_ltp2.rb +20 -0
  75. data/tests/test_many_fds.rb +22 -0
  76. data/tests/test_pause.rb +29 -0
  77. data/tests/test_pool.rb +2 -0
  78. data/tests/test_process_watch.rb +2 -0
  79. data/tests/test_processes.rb +7 -7
  80. data/tests/test_queue.rb +14 -0
  81. data/tests/test_resolver.rb +56 -7
  82. data/tests/test_set_sock_opt.rb +2 -0
  83. data/tests/test_smtpclient.rb +20 -0
  84. data/tests/test_ssl_args.rb +2 -2
  85. data/tests/test_ssl_dhparam.rb +83 -0
  86. data/tests/test_ssl_ecdh_curve.rb +79 -0
  87. data/tests/test_ssl_extensions.rb +49 -0
  88. data/tests/test_ssl_methods.rb +22 -5
  89. data/tests/test_ssl_protocols.rb +246 -0
  90. data/tests/test_ssl_verify.rb +103 -59
  91. data/tests/test_system.rb +4 -0
  92. data/tests/test_threaded_resource.rb +8 -0
  93. data/tests/test_unbind_reason.rb +5 -1
  94. metadata +173 -107
  95. data/.gitignore +0 -21
  96. data/.travis.yml +0 -12
  97. data/.yardopts +0 -7
  98. data/Gemfile +0 -2
  99. data/Rakefile +0 -20
  100. data/eventmachine.gemspec +0 -36
  101. data/rakelib/cpp.rake_example +0 -77
@@ -45,7 +45,7 @@ class TestSslArgs < Test::Unit::TestCase
45
45
  def test_tls_params_file_doesnt_exist
46
46
  priv_file, cert_file = 'foo_priv_key', 'bar_cert_file'
47
47
  [priv_file, cert_file].all? do |f|
48
- assert(!File.exists?(f), "Cert file #{f} seems to exist, and should not for the tests")
48
+ assert(!File.exist?(f), "Cert file #{f} seems to exist, and should not for the tests")
49
49
  end
50
50
 
51
51
  # associate_callback_target is a pain! (build!)
@@ -75,4 +75,4 @@ class TestSslArgs < Test::Unit::TestCase
75
75
  assert(false, 'should not have raised an exception')
76
76
  end
77
77
  end
78
- end if EM.ssl?
78
+ end if EM.ssl?
@@ -0,0 +1,83 @@
1
+ require 'em_test_helper'
2
+
3
+ class TestSslDhParam < Test::Unit::TestCase
4
+ def setup
5
+ $dir = File.dirname(File.expand_path(__FILE__)) + '/'
6
+ $dhparam_file = File.join($dir, 'dhparam.pem')
7
+ end
8
+
9
+ module Client
10
+ def connection_completed
11
+ start_tls
12
+ end
13
+
14
+ def ssl_handshake_completed
15
+ $client_handshake_completed = true
16
+ $client_cipher_name = get_cipher_name
17
+ close_connection
18
+ end
19
+
20
+ def unbind
21
+ EM.stop_event_loop
22
+ end
23
+ end
24
+
25
+ module Server
26
+ def post_init
27
+ start_tls(:dhparam => $dhparam_file, :cipher_list => "DHE,EDH")
28
+ end
29
+
30
+ def ssl_handshake_completed
31
+ $server_handshake_completed = true
32
+ $server_cipher_name = get_cipher_name
33
+ end
34
+ end
35
+
36
+ module NoDhServer
37
+ def post_init
38
+ start_tls(:cipher_list => "DHE,EDH")
39
+ end
40
+
41
+ def ssl_handshake_completed
42
+ $server_handshake_completed = true
43
+ $server_cipher_name = get_cipher_name
44
+ end
45
+ end
46
+
47
+ def test_no_dhparam
48
+ omit_unless(EM.ssl?)
49
+ omit_if(rbx?)
50
+
51
+ $client_handshake_completed, $server_handshake_completed = false, false
52
+ $server_cipher_name, $client_cipher_name = nil, nil
53
+
54
+ EM.run {
55
+ EM.start_server("127.0.0.1", 16784, NoDhServer)
56
+ EM.connect("127.0.0.1", 16784, Client)
57
+ }
58
+
59
+ assert(!$client_handshake_completed)
60
+ assert(!$server_handshake_completed)
61
+ end
62
+
63
+ def test_dhparam
64
+ omit_unless(EM.ssl?)
65
+ omit_if(rbx?)
66
+
67
+ $client_handshake_completed, $server_handshake_completed = false, false
68
+ $server_cipher_name, $client_cipher_name = nil, nil
69
+
70
+ EM.run {
71
+ EM.start_server("127.0.0.1", 16784, Server)
72
+ EM.connect("127.0.0.1", 16784, Client)
73
+ }
74
+
75
+ assert($client_handshake_completed)
76
+ assert($server_handshake_completed)
77
+
78
+ assert($client_cipher_name.length > 0)
79
+ assert_equal($client_cipher_name, $server_cipher_name)
80
+
81
+ assert_match(/^(DHE|EDH)/, $client_cipher_name)
82
+ end
83
+ end
@@ -0,0 +1,79 @@
1
+ require 'em_test_helper'
2
+
3
+ class TestSslEcdhCurve < Test::Unit::TestCase
4
+ module Client
5
+ def connection_completed
6
+ start_tls
7
+ end
8
+
9
+ def ssl_handshake_completed
10
+ $client_handshake_completed = true
11
+ $client_cipher_name = get_cipher_name
12
+ close_connection
13
+ end
14
+
15
+ def unbind
16
+ EM.stop_event_loop
17
+ end
18
+ end
19
+
20
+ module Server
21
+ def post_init
22
+ start_tls(:ecdh_curve => "prime256v1", :cipher_list => "ECDH")
23
+ end
24
+
25
+ def ssl_handshake_completed
26
+ $server_handshake_completed = true
27
+ $server_cipher_name = get_cipher_name
28
+ end
29
+ end
30
+
31
+ module NoCurveServer
32
+ def post_init
33
+ start_tls(:cipher_list => "ECDH")
34
+ end
35
+
36
+ def ssl_handshake_completed
37
+ $server_handshake_completed = true
38
+ $server_cipher_name = get_cipher_name
39
+ end
40
+ end
41
+
42
+ def test_no_ecdh_curve
43
+ omit_unless(EM.ssl?)
44
+ omit_if(rbx?)
45
+
46
+ $client_handshake_completed, $server_handshake_completed = false, false
47
+
48
+ EM.run {
49
+ EM.start_server("127.0.0.1", 16784, NoCurveServer)
50
+ EM.connect("127.0.0.1", 16784, Client)
51
+ }
52
+
53
+ assert(!$client_handshake_completed)
54
+ assert(!$server_handshake_completed)
55
+ end
56
+
57
+ def test_ecdh_curve
58
+ omit_unless(EM.ssl?)
59
+ omit_if(rbx?)
60
+
61
+ $client_handshake_completed, $server_handshake_completed = false, false
62
+ $server_cipher_name, $client_cipher_name = nil, nil
63
+
64
+ EM.run {
65
+ EM.start_server("127.0.0.1", 16784, Server)
66
+ EM.connect("127.0.0.1", 16784, Client)
67
+ }
68
+
69
+ assert($client_handshake_completed)
70
+ assert($server_handshake_completed)
71
+
72
+ assert($client_cipher_name.length > 0)
73
+ assert_equal($client_cipher_name, $server_cipher_name)
74
+
75
+ assert_match(/^(AECDH|ECDHE)/, $client_cipher_name)
76
+ end
77
+
78
+
79
+ end
@@ -0,0 +1,49 @@
1
+ require 'em_test_helper'
2
+
3
+ require 'socket'
4
+ require 'openssl'
5
+
6
+ if EM.ssl?
7
+ class TestSslExtensions < Test::Unit::TestCase
8
+
9
+ module Client
10
+ def ssl_handshake_completed
11
+ $client_handshake_completed = true
12
+ close_connection
13
+ end
14
+
15
+ def unbind
16
+ EM.stop_event_loop
17
+ end
18
+
19
+ def connection_completed
20
+ start_tls(:ssl_version => :tlsv1, :sni_hostname => 'example.com')
21
+ end
22
+ end
23
+
24
+ module Server
25
+ def ssl_handshake_completed
26
+ $server_handshake_completed = true
27
+ $server_sni_hostname = get_sni_hostname
28
+ end
29
+
30
+ def post_init
31
+ start_tls(:ssl_version => :TLSv1)
32
+ end
33
+ end
34
+
35
+ def test_tlsext_sni_hostname
36
+ $server_handshake_completed = false
37
+
38
+ EM.run do
39
+ EM.start_server("127.0.0.1", 16784, Server)
40
+ EM.connect("127.0.0.1", 16784, Client)
41
+ end
42
+
43
+ assert($server_handshake_completed)
44
+ assert_equal('example.com', $server_sni_hostname)
45
+ end
46
+ end
47
+ else
48
+ warn "EM built without SSL support, skipping tests in #{__FILE__}"
49
+ end
@@ -3,7 +3,6 @@ require 'em_test_helper'
3
3
  class TestSSLMethods < Test::Unit::TestCase
4
4
 
5
5
  module ServerHandler
6
-
7
6
  def post_init
8
7
  start_tls
9
8
  end
@@ -11,12 +10,13 @@ class TestSSLMethods < Test::Unit::TestCase
11
10
  def ssl_handshake_completed
12
11
  $server_called_back = true
13
12
  $server_cert_value = get_peer_cert
13
+ $server_cipher_bits = get_cipher_bits
14
+ $server_cipher_name = get_cipher_name
15
+ $server_cipher_protocol = get_cipher_protocol
14
16
  end
15
-
16
17
  end
17
18
 
18
19
  module ClientHandler
19
-
20
20
  def post_init
21
21
  start_tls
22
22
  end
@@ -24,14 +24,21 @@ class TestSSLMethods < Test::Unit::TestCase
24
24
  def ssl_handshake_completed
25
25
  $client_called_back = true
26
26
  $client_cert_value = get_peer_cert
27
+ $client_cipher_bits = get_cipher_bits
28
+ $client_cipher_name = get_cipher_name
29
+ $client_cipher_protocol = get_cipher_protocol
27
30
  EM.stop_event_loop
28
31
  end
29
-
30
32
  end
31
33
 
32
34
  def test_ssl_methods
35
+ omit_unless(EM.ssl?)
36
+ omit_if(rbx?)
33
37
  $server_called_back, $client_called_back = false, false
34
38
  $server_cert_value, $client_cert_value = nil, nil
39
+ $server_cipher_bits, $client_cipher_bits = nil, nil
40
+ $server_cipher_name, $client_cipher_name = nil, nil
41
+ $server_cipher_protocol, $client_cipher_protocol = nil, nil
35
42
 
36
43
  EM.run {
37
44
  EM.start_server("127.0.0.1", 9999, ServerHandler)
@@ -43,6 +50,16 @@ class TestSSLMethods < Test::Unit::TestCase
43
50
 
44
51
  assert($server_cert_value.is_a?(NilClass))
45
52
  assert($client_cert_value.is_a?(String))
53
+
54
+ assert($client_cipher_bits > 0)
55
+ assert_equal($client_cipher_bits, $server_cipher_bits)
56
+
57
+ assert($client_cipher_name.length > 0)
58
+ assert_match(/AES/, $client_cipher_name)
59
+ assert_equal($client_cipher_name, $server_cipher_name)
60
+
61
+ assert_match(/TLS/, $client_cipher_protocol)
62
+ assert_equal($client_cipher_protocol, $server_cipher_protocol)
46
63
  end
47
64
 
48
- end if EM.ssl?
65
+ end
@@ -0,0 +1,246 @@
1
+ require 'em_test_helper'
2
+
3
+ require 'socket'
4
+ require 'openssl'
5
+
6
+ if EM.ssl?
7
+ class TestSslProtocols < Test::Unit::TestCase
8
+
9
+ module Client
10
+ def ssl_handshake_completed
11
+ $client_handshake_completed = true
12
+ close_connection
13
+ end
14
+
15
+ def unbind
16
+ EM.stop_event_loop
17
+ end
18
+ end
19
+
20
+ module Server
21
+ def ssl_handshake_completed
22
+ $server_handshake_completed = true
23
+ end
24
+ end
25
+
26
+ module ClientAny
27
+ include Client
28
+ def connection_completed
29
+ start_tls(:ssl_version => %w(sslv2 sslv3 tlsv1 tlsv1_1 tlsv1_2))
30
+ end
31
+ end
32
+
33
+ module ClientDefault
34
+ include Client
35
+ def connection_completed
36
+ start_tls
37
+ end
38
+ end
39
+
40
+ module ClientSSLv3
41
+ include Client
42
+ def connection_completed
43
+ start_tls(:ssl_version => %w(SSLv3))
44
+ end
45
+ end
46
+
47
+ module ServerSSLv3
48
+ include Server
49
+ def post_init
50
+ start_tls(:ssl_version => %w(SSLv3))
51
+ end
52
+ end
53
+
54
+ module ServerTLSv1CaseInsensitive
55
+ include Server
56
+ def post_init
57
+ start_tls(:ssl_version => %w(tlsv1))
58
+ end
59
+ end
60
+
61
+ module ServerAny
62
+ include Server
63
+ def post_init
64
+ start_tls(:ssl_version => %w(sslv2 sslv3 tlsv1 tlsv1_1 tlsv1_2))
65
+ end
66
+ end
67
+
68
+ module ServerDefault
69
+ include Server
70
+ def post_init
71
+ start_tls
72
+ end
73
+ end
74
+
75
+ module InvalidProtocol
76
+ include Client
77
+ def post_init
78
+ start_tls(:ssl_version => %w(tlsv1 badinput))
79
+ end
80
+ end
81
+
82
+ def test_invalid_ssl_version
83
+ assert_raises(RuntimeError, "Unrecognized SSL/TLS Version: badinput") do
84
+ EM.run do
85
+ EM.start_server("127.0.0.1", 16784, InvalidProtocol)
86
+ EM.connect("127.0.0.1", 16784, InvalidProtocol)
87
+ end
88
+ end
89
+ end
90
+
91
+ def test_any_to_v3
92
+ $client_handshake_completed, $server_handshake_completed = false, false
93
+ EM.run do
94
+ EM.start_server("127.0.0.1", 16784, ServerSSLv3)
95
+ EM.connect("127.0.0.1", 16784, ClientAny)
96
+ end
97
+
98
+ assert($client_handshake_completed)
99
+ assert($server_handshake_completed)
100
+ end
101
+
102
+ def test_case_insensitivity
103
+ $client_handshake_completed, $server_handshake_completed = false, false
104
+ EM.run do
105
+ EM.start_server("127.0.0.1", 16784, ServerTLSv1CaseInsensitive)
106
+ EM.connect("127.0.0.1", 16784, ClientAny)
107
+ end
108
+
109
+ assert($client_handshake_completed)
110
+ assert($server_handshake_completed)
111
+ end
112
+
113
+ def test_v3_to_any
114
+ $client_handshake_completed, $server_handshake_completed = false, false
115
+ EM.run do
116
+ EM.start_server("127.0.0.1", 16784, ServerAny)
117
+ EM.connect("127.0.0.1", 16784, ClientSSLv3)
118
+ end
119
+
120
+ assert($client_handshake_completed)
121
+ assert($server_handshake_completed)
122
+ end
123
+
124
+ def test_v3_to_v3
125
+ $client_handshake_completed, $server_handshake_completed = false, false
126
+ EM.run do
127
+ EM.start_server("127.0.0.1", 16784, ServerSSLv3)
128
+ EM.connect("127.0.0.1", 16784, ClientSSLv3)
129
+ end
130
+
131
+ assert($client_handshake_completed)
132
+ assert($server_handshake_completed)
133
+ end
134
+
135
+ def test_any_to_any
136
+ $client_handshake_completed, $server_handshake_completed = false, false
137
+ EM.run do
138
+ EM.start_server("127.0.0.1", 16784, ServerAny)
139
+ EM.connect("127.0.0.1", 16784, ClientAny)
140
+ end
141
+
142
+ assert($client_handshake_completed)
143
+ assert($server_handshake_completed)
144
+ end
145
+
146
+ def test_default_to_default
147
+ $client_handshake_completed, $server_handshake_completed = false, false
148
+ EM.run do
149
+ EM.start_server("127.0.0.1", 16784, ServerDefault)
150
+ EM.connect("127.0.0.1", 16784, ClientDefault)
151
+ end
152
+
153
+ assert($client_handshake_completed)
154
+ assert($server_handshake_completed)
155
+ end
156
+
157
+ module ServerV3StopAfterHandshake
158
+ def post_init
159
+ start_tls(:ssl_version => %w(SSLv3))
160
+ end
161
+
162
+ def ssl_handshake_completed
163
+ $server_handshake_completed = true
164
+ EM.stop_event_loop
165
+ end
166
+ end
167
+
168
+ module ServerTLSv1StopAfterHandshake
169
+ def post_init
170
+ start_tls(:ssl_version => %w(TLSv1))
171
+ end
172
+
173
+ def ssl_handshake_completed
174
+ $server_handshake_completed = true
175
+ EM.stop_event_loop
176
+ end
177
+ end
178
+
179
+ def test_v3_with_external_client
180
+ $server_handshake_completed = false
181
+ EM.run do
182
+ setup_timeout(2)
183
+ EM.start_server("127.0.0.1", 16784, ServerV3StopAfterHandshake)
184
+ EM.defer do
185
+ sock = TCPSocket.new("127.0.0.1", 16784)
186
+ ctx = OpenSSL::SSL::SSLContext.new
187
+ ctx.ssl_version = :SSLv3_client
188
+ ssl = OpenSSL::SSL::SSLSocket.new(sock, ctx)
189
+ ssl.connect
190
+ ssl.close rescue nil
191
+ sock.close rescue nil
192
+ end
193
+ end
194
+
195
+ assert($server_handshake_completed)
196
+ end
197
+
198
+ def test_tlsv1_with_external_client
199
+ $server_handshake_completed = false
200
+ EM.run do
201
+ setup_timeout(2)
202
+ EM.start_server("127.0.0.1", 16784, ServerTLSv1StopAfterHandshake)
203
+ EM.defer do
204
+ sock = TCPSocket.new("127.0.0.1", 16784)
205
+ ctx = OpenSSL::SSL::SSLContext.new
206
+ ctx.ssl_version = :TLSv1_client
207
+ ssl = OpenSSL::SSL::SSLSocket.new(sock, ctx)
208
+ ssl.connect
209
+ ssl.close rescue nil
210
+ sock.close rescue nil
211
+ end
212
+ end
213
+
214
+ assert($server_handshake_completed)
215
+ end
216
+
217
+ def test_tlsv1_required_with_external_client
218
+ $server_handshake_completed = false
219
+
220
+ EM.run do
221
+ n = 0
222
+ EM.add_periodic_timer(0.5) do
223
+ n += 1
224
+ (EM.stop rescue nil) if n == 2
225
+ end
226
+ EM.start_server("127.0.0.1", 16784, ServerTLSv1StopAfterHandshake)
227
+ EM.defer do
228
+ sock = TCPSocket.new("127.0.0.1", 16784)
229
+ ctx = OpenSSL::SSL::SSLContext.new
230
+ ctx.ssl_version = :SSLv3_client
231
+ ssl = OpenSSL::SSL::SSLSocket.new(sock, ctx)
232
+ assert_raise OpenSSL::SSL::SSLError do
233
+ ssl.connect
234
+ end
235
+ ssl.close rescue nil
236
+ sock.close rescue nil
237
+ EM.stop rescue nil
238
+ end
239
+ end
240
+
241
+ assert(!$server_handshake_completed)
242
+ end
243
+ end
244
+ else
245
+ warn "EM built without SSL support, skipping tests in #{__FILE__}"
246
+ end