eventmachine 0.12.8-x86-mswin32-60 → 0.12.10-x86-mswin32-60

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. data/.gitignore +14 -13
  2. data/Rakefile +374 -264
  3. data/eventmachine.gemspec +4 -5
  4. data/ext/binder.cpp +125 -126
  5. data/ext/binder.h +46 -48
  6. data/ext/cmain.cpp +184 -42
  7. data/ext/cplusplus.cpp +202 -202
  8. data/ext/ed.cpp +242 -81
  9. data/ext/ed.h +39 -22
  10. data/ext/em.cpp +127 -108
  11. data/ext/em.h +27 -18
  12. data/ext/emwin.cpp +3 -3
  13. data/ext/eventmachine.h +49 -38
  14. data/ext/eventmachine_cpp.h +96 -96
  15. data/ext/extconf.rb +147 -132
  16. data/ext/fastfilereader/extconf.rb +82 -76
  17. data/ext/project.h +151 -140
  18. data/ext/rubymain.cpp +222 -103
  19. data/ext/ssl.cpp +460 -460
  20. data/ext/ssl.h +94 -94
  21. data/java/src/com/rubyeventmachine/EmReactor.java +570 -423
  22. data/java/src/com/rubyeventmachine/EventableChannel.java +69 -57
  23. data/java/src/com/rubyeventmachine/EventableDatagramChannel.java +189 -171
  24. data/java/src/com/rubyeventmachine/EventableSocketChannel.java +364 -244
  25. data/java/src/com/rubyeventmachine/{Application.java → application/Application.java} +194 -200
  26. data/java/src/com/rubyeventmachine/{Connection.java → application/Connection.java} +74 -74
  27. data/java/src/com/rubyeventmachine/{ConnectionFactory.java → application/ConnectionFactory.java} +36 -36
  28. data/java/src/com/rubyeventmachine/{DefaultConnectionFactory.java → application/DefaultConnectionFactory.java} +46 -46
  29. data/java/src/com/rubyeventmachine/{PeriodicTimer.java → application/PeriodicTimer.java} +38 -38
  30. data/java/src/com/rubyeventmachine/{Timer.java → application/Timer.java} +54 -54
  31. data/java/src/com/rubyeventmachine/tests/ApplicationTest.java +109 -108
  32. data/java/src/com/rubyeventmachine/tests/ConnectTest.java +148 -146
  33. data/java/src/com/rubyeventmachine/tests/TestDatagrams.java +53 -53
  34. data/java/src/com/rubyeventmachine/tests/TestServers.java +75 -74
  35. data/java/src/com/rubyeventmachine/tests/TestTimers.java +90 -89
  36. data/lib/em/connection.rb +71 -12
  37. data/lib/em/deferrable.rb +191 -186
  38. data/lib/em/protocols.rb +36 -35
  39. data/lib/em/protocols/httpclient2.rb +590 -582
  40. data/lib/em/protocols/line_and_text.rb +125 -126
  41. data/lib/em/protocols/linetext2.rb +161 -160
  42. data/lib/em/protocols/object_protocol.rb +45 -39
  43. data/lib/em/protocols/smtpclient.rb +357 -331
  44. data/lib/em/protocols/socks4.rb +66 -0
  45. data/lib/em/queue.rb +60 -60
  46. data/lib/em/timers.rb +56 -55
  47. data/lib/em/version.rb +1 -1
  48. data/lib/eventmachine.rb +125 -169
  49. data/lib/jeventmachine.rb +257 -142
  50. data/tasks/{cpp.rake → cpp.rake_example} +76 -76
  51. data/tests/test_attach.rb +125 -100
  52. data/tests/test_basic.rb +1 -2
  53. data/tests/test_connection_count.rb +34 -44
  54. data/tests/test_epoll.rb +0 -2
  55. data/tests/test_get_sock_opt.rb +30 -0
  56. data/tests/test_httpclient2.rb +3 -3
  57. data/tests/test_inactivity_timeout.rb +21 -1
  58. data/tests/test_ltp.rb +182 -188
  59. data/tests/test_next_tick.rb +0 -2
  60. data/tests/test_pause.rb +70 -0
  61. data/tests/test_pending_connect_timeout.rb +48 -0
  62. data/tests/test_ssl_args.rb +78 -67
  63. data/tests/test_timers.rb +162 -141
  64. metadata +13 -11
  65. data/tasks/project.rake +0 -79
  66. data/tasks/tests.rake +0 -193
@@ -33,7 +33,6 @@ class TestNextTick < Test::Unit::TestCase
33
33
 
34
34
  def test_tick_arg
35
35
  pr = proc {EM.stop}
36
- EM.epoll
37
36
  EM.run {
38
37
  EM.next_tick pr
39
38
  }
@@ -41,7 +40,6 @@ class TestNextTick < Test::Unit::TestCase
41
40
  end
42
41
 
43
42
  def test_tick_block
44
- EM.epoll
45
43
  EM.run {
46
44
  EM.next_tick {EM.stop}
47
45
  }
@@ -0,0 +1,70 @@
1
+ $:.unshift File.expand_path(File.dirname(__FILE__) + "/../lib")
2
+ require 'eventmachine'
3
+ require 'socket'
4
+ require 'test/unit'
5
+
6
+ class TestPause < Test::Unit::TestCase
7
+ TestHost = "127.0.0.1"
8
+ TestPort = 9070
9
+
10
+ def setup
11
+ assert(!EM.reactor_running?)
12
+ end
13
+
14
+ def teardown
15
+ assert(!EM.reactor_running?)
16
+ end
17
+
18
+ #-------------------------------------
19
+
20
+ def test_pause_resume
21
+ test = self
22
+ server = nil
23
+
24
+ s_rx = c_rx = 0
25
+
26
+ EM.run do
27
+ EM.start_server TestHost, TestPort, Module.new {
28
+ define_method :post_init do
29
+ server = self
30
+ end
31
+
32
+ define_method :receive_data do |data|
33
+ s_rx += 1
34
+
35
+ EM.add_periodic_timer(0.01) { send_data 'hi' }
36
+ send_data 'hi'
37
+
38
+ # pause server, now no outgoing data will actually
39
+ # be sent and no more incoming data will be received
40
+ pause
41
+ end
42
+ }
43
+
44
+ c = EM.connect TestHost, TestPort, Module.new {
45
+ define_method :receive_data do |data|
46
+ c_rx += 1
47
+ end
48
+ }
49
+ EM.add_periodic_timer(0.01) { c.send_data 'hi' }
50
+
51
+ EM.add_timer(1) do
52
+ test.assert_equal 1, s_rx
53
+ test.assert_equal 0, c_rx
54
+ test.assert server.paused?
55
+
56
+ # resume server, queued outgoing and incoming data will be flushed
57
+ server.resume
58
+
59
+ test.assert ! server.paused?
60
+
61
+ EM.add_timer(1) do
62
+ test.assert server.paused?
63
+ test.assert s_rx >= 2
64
+ test.assert c_rx >= 1
65
+ EM.stop_event_loop
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,48 @@
1
+ $:.unshift "../lib"
2
+ require 'eventmachine'
3
+ require 'test/unit'
4
+
5
+ class TestPendingConnectTimeout < Test::Unit::TestCase
6
+
7
+ def test_default
8
+ $timeout = nil
9
+ EM.run {
10
+ c = EM.connect("127.0.0.1", 54321)
11
+ $timeout = c.pending_connect_timeout
12
+ EM.stop
13
+ }
14
+
15
+ assert_equal(20.0, $timeout)
16
+ end
17
+
18
+ def test_set_and_get
19
+ $timeout = nil
20
+ EM.run {
21
+ c = EM.connect("1.2.3.4", 54321)
22
+ c.pending_connect_timeout = 2.5
23
+ $timeout = c.pending_connect_timeout
24
+ EM.stop
25
+ }
26
+
27
+ assert_equal(2.5, $timeout)
28
+ end
29
+
30
+ module TimeoutHandler
31
+ def unbind
32
+ EM.stop
33
+ end
34
+ end
35
+
36
+ def test_for_real
37
+ $timeout = nil
38
+ EM.run {
39
+ EM.heartbeat_interval = 0.1
40
+ $start = Time.now
41
+ c = EM.connect("1.2.3.4", 54321, TimeoutHandler)
42
+ c.pending_connect_timeout = 5
43
+ }
44
+
45
+ assert_in_delta(5, (Time.now - $start), 0.3)
46
+ end
47
+
48
+ end
@@ -1,68 +1,79 @@
1
- require "test/unit"
2
- require 'tempfile'
3
-
4
- $:.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
5
- require "eventmachine"
6
-
7
- module EventMachine
8
- def self._set_mocks
9
- class <<self
10
- alias set_tls_parms_old set_tls_parms
11
- alias start_tls_old start_tls
12
- def set_tls_parms *args; end
13
- def start_tls *args; end
14
- end
15
- end
16
-
17
- def self._clear_mocks
18
- class <<self
19
- alias set_tls_parms set_tls_parms_old
20
- alias start_tls start_tls_old
21
- end
22
- end
23
- end
24
-
25
-
26
- class TestSslArgs < Test::Unit::TestCase
27
- def setup
28
- EventMachine._set_mocks
29
- end
30
-
31
- def teardown
32
- EventMachine._clear_mocks
33
- end
34
-
35
- def test_tls_params_file_doesnt_exist
36
- priv_file, cert_file = 'foo_priv_key', 'bar_cert_file'
37
- [priv_file, cert_file].all? do |f|
38
- assert(!File.exists?(f), "Cert file #{f} seems to exist, and should not for the tests")
39
- end
40
-
41
- # associate_callback_target is a pain! (build!)
42
- conn = EventMachine::Connection.new('foo')
43
-
44
- assert_raises(EventMachine::FileNotFoundException) do
45
- conn.start_tls(:private_key_file => priv_file)
46
- end
47
- assert_raises(EventMachine::FileNotFoundException) do
48
- conn.start_tls(:cert_chain_file => cert_file)
49
- end
50
- assert_raises(EventMachine::FileNotFoundException) do
51
- conn.start_tls(:private_key_file => priv_file, :cert_chain_file => cert_file)
52
- end
53
- end
54
-
55
- def test_tls_params_file_does_exist
56
- priv_file = Tempfile.new('em_test')
57
- cert_file = Tempfile.new('em_test')
58
- priv_file_path = priv_file.path
59
- cert_file_path = cert_file.path
60
- conn = EventMachine::Connection.new('foo')
61
- params = {:private_key_file => priv_file_path, :cert_chain_file => cert_file_path}
62
- begin
63
- conn.start_tls params
64
- rescue Object
65
- assert(false, 'should not have raised an exception')
66
- end
67
- end
1
+ require "test/unit"
2
+ require 'tempfile'
3
+
4
+ $:.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
5
+ require "eventmachine"
6
+
7
+ module EventMachine
8
+ def self._set_mocks
9
+ class <<self
10
+ alias set_tls_parms_old set_tls_parms
11
+ alias start_tls_old start_tls
12
+ begin
13
+ old, $VERBOSE = $VERBOSE, nil
14
+ def set_tls_parms *args; end
15
+ def start_tls *args; end
16
+ ensure
17
+ $VERBOSE = old
18
+ end
19
+ end
20
+ end
21
+
22
+ def self._clear_mocks
23
+ class <<self
24
+ begin
25
+ old, $VERBOSE = $VERBOSE, nil
26
+ alias set_tls_parms set_tls_parms_old
27
+ alias start_tls start_tls_old
28
+ ensure
29
+ $VERBOSE = old
30
+ end
31
+ end
32
+ end
33
+ end
34
+
35
+
36
+
37
+ class TestSslArgs < Test::Unit::TestCase
38
+ def setup
39
+ EventMachine._set_mocks
40
+ end
41
+
42
+ def teardown
43
+ EventMachine._clear_mocks
44
+ end
45
+
46
+ def test_tls_params_file_doesnt_exist
47
+ priv_file, cert_file = 'foo_priv_key', 'bar_cert_file'
48
+ [priv_file, cert_file].all? do |f|
49
+ assert(!File.exists?(f), "Cert file #{f} seems to exist, and should not for the tests")
50
+ end
51
+
52
+ # associate_callback_target is a pain! (build!)
53
+ conn = EventMachine::Connection.new('foo')
54
+
55
+ assert_raises(EventMachine::FileNotFoundException) do
56
+ conn.start_tls(:private_key_file => priv_file)
57
+ end
58
+ assert_raises(EventMachine::FileNotFoundException) do
59
+ conn.start_tls(:cert_chain_file => cert_file)
60
+ end
61
+ assert_raises(EventMachine::FileNotFoundException) do
62
+ conn.start_tls(:private_key_file => priv_file, :cert_chain_file => cert_file)
63
+ end
64
+ end
65
+
66
+ def test_tls_params_file_does_exist
67
+ priv_file = Tempfile.new('em_test')
68
+ cert_file = Tempfile.new('em_test')
69
+ priv_file_path = priv_file.path
70
+ cert_file_path = cert_file.path
71
+ conn = EventMachine::Connection.new('foo')
72
+ params = {:private_key_file => priv_file_path, :cert_chain_file => cert_file_path}
73
+ begin
74
+ conn.start_tls params
75
+ rescue Object
76
+ assert(false, 'should not have raised an exception')
77
+ end
78
+ end
68
79
  end if EM.ssl?
@@ -1,141 +1,162 @@
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
- $:.unshift "../lib"
29
- require 'eventmachine'
30
- require 'test/unit'
31
-
32
- class TestTimers < Test::Unit::TestCase
33
-
34
- def test_timer_with_block
35
- x = false
36
- EventMachine.run {
37
- EventMachine::Timer.new(0.25) {
38
- x = true
39
- EventMachine.stop
40
- }
41
- }
42
- assert x
43
- end
44
-
45
- def test_timer_with_proc
46
- x = false
47
- EventMachine.run {
48
- EventMachine::Timer.new(0.25, proc {
49
- x = true
50
- EventMachine.stop
51
- })
52
- }
53
- assert x
54
- end
55
-
56
- def test_timer_cancel
57
- x = true
58
- EventMachine.run {
59
- timer = EventMachine::Timer.new(0.25, proc { x = false })
60
- timer.cancel
61
- EventMachine::Timer.new(0.5, proc {EventMachine.stop})
62
- }
63
- assert x
64
- end
65
-
66
- def test_periodic_timer
67
- x = 0
68
- EventMachine.run {
69
- EventMachine::PeriodicTimer.new(0.1) do
70
- x += 1
71
- EventMachine.stop if x == 4
72
- end
73
- }
74
- assert( x == 4 )
75
- end
76
-
77
- def test_periodic_timer_cancel
78
- x = 0
79
- EventMachine.run {
80
- pt = EventMachine::PeriodicTimer.new(0.25, proc { x += 1 })
81
- pt.cancel
82
- EventMachine::Timer.new(0.5) {EventMachine.stop}
83
- }
84
- assert( x == 0 )
85
- end
86
-
87
- def test_periodic_timer_self_cancel
88
- x = 0
89
- EventMachine.run {
90
- pt = EventMachine::PeriodicTimer.new(0.1) {
91
- x += 1
92
- if x == 4
93
- pt.cancel
94
- EventMachine.stop
95
- end
96
- }
97
- }
98
- assert( x == 4 )
99
- end
100
-
101
-
102
- # This test is only applicable to compiled versions of the reactor.
103
- # Pure ruby and java versions have no built-in limit on the number of outstanding timers.
104
- #
105
- def test_timer_change_max_outstanding
106
- ten_thousand_timers = proc {
107
- 10000.times {
108
- EM.add_timer(5) {}
109
- }
110
- }
111
-
112
- EM.run {
113
- if EM.library_type == :pure_ruby
114
- ten_thousand_timers.call
115
- elsif EM.library_type == :java
116
- ten_thousand_timers.call
117
- else
118
- begin
119
- assert_raises( RuntimeError ) {
120
- ten_thousand_timers.call
121
- }
122
- rescue Object
123
- p $!
124
- assert(false, $!.message)
125
- end
126
- end
127
- EM.stop
128
- }
129
-
130
- assert(!EM.reactor_running?, 'Reactor running when it should not be.')
131
- assert( EM.get_max_timers != 10001 )
132
- EM.set_max_timers( 10001 )
133
- assert( EM.get_max_timers == 10001 )
134
-
135
- EM.run {
136
- ten_thousand_timers.call
137
- EM.stop
138
- }
139
- end
140
-
141
- end
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
+ $:.unshift "../lib"
29
+ require 'eventmachine'
30
+ require 'test/unit'
31
+
32
+ class TestTimers < Test::Unit::TestCase
33
+
34
+ def test_timer_with_block
35
+ x = false
36
+ EventMachine.run {
37
+ EventMachine::Timer.new(0.25) {
38
+ x = true
39
+ EventMachine.stop
40
+ }
41
+ }
42
+ assert x
43
+ end
44
+
45
+ def test_timer_with_proc
46
+ x = false
47
+ EventMachine.run {
48
+ EventMachine::Timer.new(0.25, proc {
49
+ x = true
50
+ EventMachine.stop
51
+ })
52
+ }
53
+ assert x
54
+ end
55
+
56
+ def test_timer_cancel
57
+ x = true
58
+ EventMachine.run {
59
+ timer = EventMachine::Timer.new(0.25, proc { x = false })
60
+ timer.cancel
61
+ EventMachine::Timer.new(0.5, proc {EventMachine.stop})
62
+ }
63
+ assert x
64
+ end
65
+
66
+ def test_periodic_timer
67
+ x = 0
68
+ EventMachine.run {
69
+ EventMachine::PeriodicTimer.new(0.1) do
70
+ x += 1
71
+ EventMachine.stop if x == 4
72
+ end
73
+ }
74
+ assert( x == 4 )
75
+ end
76
+
77
+ def test_add_periodic_timer
78
+ x = 0
79
+ EM.run {
80
+ t = EM.add_periodic_timer(0.1) do
81
+ x += 1
82
+ EM.stop if x == 4
83
+ end
84
+ assert t.respond_to?(:cancel)
85
+ }
86
+ end
87
+
88
+ def test_periodic_timer_cancel
89
+ x = 0
90
+ EventMachine.run {
91
+ pt = EventMachine::PeriodicTimer.new(0.25, proc { x += 1 })
92
+ pt.cancel
93
+ EventMachine::Timer.new(0.5) {EventMachine.stop}
94
+ }
95
+ assert( x == 0 )
96
+ end
97
+
98
+ def test_add_periodic_timer_cancel
99
+ x = 0
100
+ EventMachine.run {
101
+ pt = EM.add_periodic_timer(0.25) { x += 1 }
102
+ EM.cancel_timer(pt)
103
+ EM.add_timer(0.5) { EM.stop }
104
+ }
105
+ assert( x == 0 )
106
+ end
107
+
108
+ def test_periodic_timer_self_cancel
109
+ x = 0
110
+ EventMachine.run {
111
+ pt = EventMachine::PeriodicTimer.new(0.1) {
112
+ x += 1
113
+ if x == 4
114
+ pt.cancel
115
+ EventMachine.stop
116
+ end
117
+ }
118
+ }
119
+ assert( x == 4 )
120
+ end
121
+
122
+
123
+ # This test is only applicable to compiled versions of the reactor.
124
+ # Pure ruby and java versions have no built-in limit on the number of outstanding timers.
125
+ #
126
+ def test_timer_change_max_outstanding
127
+ ten_thousand_timers = proc {
128
+ 10001.times {
129
+ EM.add_timer(5) {}
130
+ }
131
+ }
132
+
133
+ EM.run {
134
+ if EM.library_type == :pure_ruby
135
+ ten_thousand_timers.call
136
+ elsif EM.library_type == :java
137
+ ten_thousand_timers.call
138
+ else
139
+ begin
140
+ assert_raises( RuntimeError ) {
141
+ ten_thousand_timers.call
142
+ }
143
+ rescue Object
144
+ p $!
145
+ assert(false, $!.message)
146
+ end
147
+ end
148
+ EM.stop
149
+ }
150
+
151
+ assert(!EM.reactor_running?, 'Reactor running when it should not be.')
152
+ assert( EM.get_max_timers != 10001 )
153
+ EM.set_max_timers( 10001 )
154
+ assert( EM.get_max_timers == 10001 )
155
+
156
+ EM.run {
157
+ ten_thousand_timers.call
158
+ EM.stop
159
+ }
160
+ end
161
+
162
+ end