eventmachine 0.12.6-x86-mswin32-60 → 0.12.8-x86-mswin32-60

Sign up to get free protection for your applications and to get access to all the features.
Files changed (116) hide show
  1. data/{docs/README → README} +21 -13
  2. data/Rakefile +14 -4
  3. data/docs/DEFERRABLES +0 -5
  4. data/docs/INSTALL +2 -4
  5. data/docs/LEGAL +1 -1
  6. data/docs/LIGHTWEIGHT_CONCURRENCY +0 -2
  7. data/docs/PURE_RUBY +0 -2
  8. data/docs/RELEASE_NOTES +0 -2
  9. data/docs/SMTP +0 -7
  10. data/docs/SPAWNED_PROCESSES +0 -4
  11. data/docs/TODO +0 -2
  12. data/eventmachine.gemspec +41 -32
  13. data/examples/ex_channel.rb +43 -0
  14. data/examples/ex_queue.rb +2 -0
  15. data/examples/helper.rb +2 -0
  16. data/ext/cmain.cpp +685 -586
  17. data/ext/cplusplus.cpp +15 -6
  18. data/ext/ed.cpp +1732 -1522
  19. data/ext/ed.h +407 -380
  20. data/ext/em.cpp +2263 -1937
  21. data/ext/em.h +223 -186
  22. data/ext/eventmachine.h +111 -98
  23. data/ext/eventmachine_cpp.h +1 -0
  24. data/ext/extconf.rb +4 -0
  25. data/ext/kb.cpp +81 -82
  26. data/ext/pipe.cpp +349 -351
  27. data/ext/project.h +21 -0
  28. data/ext/rubymain.cpp +1047 -847
  29. data/ext/ssl.cpp +38 -1
  30. data/ext/ssl.h +5 -1
  31. data/java/src/com/rubyeventmachine/Application.java +7 -3
  32. data/java/src/com/rubyeventmachine/EmReactor.java +16 -1
  33. data/java/src/com/rubyeventmachine/tests/ConnectTest.java +25 -3
  34. data/lib/{protocols → em}/buftok.rb +16 -5
  35. data/lib/em/callback.rb +26 -0
  36. data/lib/em/channel.rb +57 -0
  37. data/lib/em/connection.rb +505 -0
  38. data/lib/em/deferrable.rb +144 -165
  39. data/lib/em/file_watch.rb +54 -0
  40. data/lib/em/future.rb +24 -25
  41. data/lib/em/messages.rb +1 -1
  42. data/lib/em/process_watch.rb +44 -0
  43. data/lib/em/processes.rb +119 -113
  44. data/lib/em/protocols.rb +35 -0
  45. data/lib/em/protocols/header_and_content.rb +138 -0
  46. data/lib/em/protocols/httpclient.rb +263 -0
  47. data/lib/em/protocols/httpclient2.rb +582 -0
  48. data/lib/{protocols → em/protocols}/line_and_text.rb +2 -2
  49. data/lib/em/protocols/linetext2.rb +160 -0
  50. data/lib/{protocols → em/protocols}/memcache.rb +37 -7
  51. data/lib/em/protocols/object_protocol.rb +39 -0
  52. data/lib/em/protocols/postgres3.rb +247 -0
  53. data/lib/em/protocols/saslauth.rb +175 -0
  54. data/lib/em/protocols/smtpclient.rb +331 -0
  55. data/lib/em/protocols/smtpserver.rb +547 -0
  56. data/lib/em/protocols/stomp.rb +200 -0
  57. data/lib/{protocols → em/protocols}/tcptest.rb +21 -25
  58. data/lib/em/queue.rb +61 -0
  59. data/lib/em/spawnable.rb +53 -56
  60. data/lib/em/streamer.rb +92 -74
  61. data/lib/em/timers.rb +55 -0
  62. data/lib/em/version.rb +3 -0
  63. data/lib/eventmachine.rb +1636 -1926
  64. data/lib/evma.rb +1 -1
  65. data/lib/jeventmachine.rb +106 -101
  66. data/lib/pr_eventmachine.rb +47 -36
  67. data/tasks/project.rake +2 -1
  68. data/tests/client.crt +31 -0
  69. data/tests/client.key +51 -0
  70. data/tests/test_attach.rb +18 -0
  71. data/tests/test_basic.rb +285 -231
  72. data/tests/test_channel.rb +63 -0
  73. data/tests/test_connection_count.rb +2 -2
  74. data/tests/test_epoll.rb +162 -163
  75. data/tests/test_errors.rb +36 -36
  76. data/tests/test_exc.rb +22 -25
  77. data/tests/test_file_watch.rb +49 -0
  78. data/tests/test_futures.rb +77 -93
  79. data/tests/test_hc.rb +2 -2
  80. data/tests/test_httpclient.rb +55 -52
  81. data/tests/test_httpclient2.rb +153 -155
  82. data/tests/test_inactivity_timeout.rb +30 -0
  83. data/tests/test_kb.rb +8 -9
  84. data/tests/test_ltp2.rb +274 -277
  85. data/tests/test_next_tick.rb +135 -109
  86. data/tests/test_object_protocol.rb +37 -0
  87. data/tests/test_process_watch.rb +48 -0
  88. data/tests/test_processes.rb +128 -95
  89. data/tests/test_proxy_connection.rb +92 -0
  90. data/tests/test_pure.rb +1 -5
  91. data/tests/test_queue.rb +44 -0
  92. data/tests/test_running.rb +9 -14
  93. data/tests/test_sasl.rb +32 -34
  94. data/tests/test_send_file.rb +175 -176
  95. data/tests/test_servers.rb +37 -41
  96. data/tests/test_smtpserver.rb +47 -55
  97. data/tests/test_spawn.rb +284 -291
  98. data/tests/test_ssl_args.rb +1 -1
  99. data/tests/test_ssl_methods.rb +1 -1
  100. data/tests/test_ssl_verify.rb +82 -0
  101. data/tests/test_timers.rb +81 -88
  102. data/tests/test_ud.rb +0 -7
  103. data/tests/testem.rb +1 -1
  104. metadata +52 -36
  105. data/lib/em/eventable.rb +0 -39
  106. data/lib/eventmachine_version.rb +0 -31
  107. data/lib/protocols/header_and_content.rb +0 -129
  108. data/lib/protocols/httpcli2.rb +0 -803
  109. data/lib/protocols/httpclient.rb +0 -270
  110. data/lib/protocols/linetext2.rb +0 -161
  111. data/lib/protocols/postgres.rb +0 -261
  112. data/lib/protocols/saslauth.rb +0 -179
  113. data/lib/protocols/smtpclient.rb +0 -308
  114. data/lib/protocols/smtpserver.rb +0 -556
  115. data/lib/protocols/stomp.rb +0 -153
  116. data/tests/test_eventables.rb +0 -77
@@ -1,109 +1,135 @@
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
-
33
-
34
- class TestNextTick < Test::Unit::TestCase
35
-
36
- def setup
37
- end
38
-
39
- def teardown
40
- end
41
-
42
- def test_tick_arg
43
- pr = proc {EM.stop}
44
- EM.epoll
45
- EM.run {
46
- EM.next_tick pr
47
- }
48
- assert true
49
- end
50
-
51
- def test_tick_block
52
- EM.epoll
53
- EM.run {
54
- EM.next_tick {EM.stop}
55
- }
56
- assert true
57
- end
58
-
59
- # This illustrates the solution to a long-standing problem.
60
- # It's now possible to correctly nest calls to EM#run.
61
- # See the source code commentary for EM#run for more info.
62
- #
63
- def test_run_run
64
- EM.run {
65
- EM.run {
66
- EM.next_tick {EM.stop}
67
- }
68
- }
69
- end
70
-
71
- def test_pre_run_queue
72
- x = false
73
- EM.next_tick { EM.stop; x = true }
74
- EM.run { EM.add_timer(0.2) { EM.stop } }
75
- assert x
76
- end
77
-
78
- # We now support an additional parameter for EM#run.
79
- # You can pass two procs to EM#run now. The first is executed as the normal
80
- # run block. The second (if given) is scheduled for execution after the
81
- # reactor loop completes.
82
- # The reason for supporting this is subtle. There has always been an expectation
83
- # that EM#run doesn't return until after the reactor loop ends. But now it's
84
- # possible to nest calls to EM#run, which means that a nested call WILL
85
- # RETURN. In order to write code that will run correctly either way, it's
86
- # recommended to put any code which must execute after the reactor completes
87
- # in the second parameter.
88
- #
89
- def test_run_run_2
90
- a = proc {EM.stop}
91
- b = proc {assert true}
92
- EM.run a, b
93
- end
94
-
95
-
96
- # This illustrates that EM#run returns when it's called nested.
97
- # This isn't a feature, rather it's something to be wary of when writing code
98
- # that must run correctly even if EM#run is called while a reactor is already
99
- # running.
100
- def test_run_run_3
101
- a = []
102
- EM.run {
103
- EM.run proc {EM.stop}, proc {a << 2}
104
- a << 1
105
- }
106
- assert_equal( [1,2], a )
107
- end
108
-
109
- 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 TestNextTick < Test::Unit::TestCase
33
+
34
+ def test_tick_arg
35
+ pr = proc {EM.stop}
36
+ EM.epoll
37
+ EM.run {
38
+ EM.next_tick pr
39
+ }
40
+ assert true
41
+ end
42
+
43
+ def test_tick_block
44
+ EM.epoll
45
+ EM.run {
46
+ EM.next_tick {EM.stop}
47
+ }
48
+ assert true
49
+ end
50
+
51
+ # This illustrates the solution to a long-standing problem.
52
+ # It's now possible to correctly nest calls to EM#run.
53
+ # See the source code commentary for EM#run for more info.
54
+ #
55
+ def test_run_run
56
+ EM.run {
57
+ EM.run {
58
+ EM.next_tick {EM.stop}
59
+ }
60
+ }
61
+ end
62
+
63
+ def test_pre_run_queue
64
+ x = false
65
+ EM.next_tick { EM.stop; x = true }
66
+ EM.run { EM.add_timer(0.2) { EM.stop } }
67
+ assert x
68
+ end
69
+
70
+ def test_cleanup_after_stop
71
+ x = true
72
+ EM.run{
73
+ EM.next_tick{
74
+ EM.stop
75
+ EM.next_tick{ x=false }
76
+ }
77
+ }
78
+ EM.run{
79
+ EM.next_tick{ EM.stop }
80
+ }
81
+ assert x
82
+ end
83
+
84
+ # We now support an additional parameter for EM#run.
85
+ # You can pass two procs to EM#run now. The first is executed as the normal
86
+ # run block. The second (if given) is scheduled for execution after the
87
+ # reactor loop completes.
88
+ # The reason for supporting this is subtle. There has always been an expectation
89
+ # that EM#run doesn't return until after the reactor loop ends. But now it's
90
+ # possible to nest calls to EM#run, which means that a nested call WILL
91
+ # RETURN. In order to write code that will run correctly either way, it's
92
+ # recommended to put any code which must execute after the reactor completes
93
+ # in the second parameter.
94
+ #
95
+ def test_run_run_2
96
+ a = proc {EM.stop}
97
+ b = proc {assert true}
98
+ EM.run a, b
99
+ end
100
+
101
+
102
+ # This illustrates that EM#run returns when it's called nested.
103
+ # This isn't a feature, rather it's something to be wary of when writing code
104
+ # that must run correctly even if EM#run is called while a reactor is already
105
+ # running.
106
+ def test_run_run_3
107
+ a = []
108
+ EM.run {
109
+ EM.run proc {EM.stop}, proc {a << 2}
110
+ a << 1
111
+ }
112
+ assert_equal( [1,2], a )
113
+ end
114
+
115
+
116
+ def test_schedule_on_reactor_thread
117
+ x = false
118
+ EM.run do
119
+ EM.schedule { x = true }
120
+ EM.stop
121
+ end
122
+ assert x
123
+ end
124
+
125
+ def test_schedule_from_thread
126
+ x = false
127
+ EM.run do
128
+ Thread.new { EM.schedule { x = true } }.join
129
+ assert !x
130
+ EM.next_tick { EM.stop }
131
+ end
132
+ assert x
133
+ end
134
+
135
+ end
@@ -0,0 +1,37 @@
1
+ $:.unshift "../lib"
2
+ require 'eventmachine'
3
+ require 'test/unit'
4
+
5
+ class TestObjectProtocol < Test::Unit::TestCase
6
+ Host = "127.0.0.1"
7
+ Port = 9550
8
+
9
+ module Server
10
+ include EM::P::ObjectProtocol
11
+ def post_init
12
+ send_object :hello=>'world'
13
+ end
14
+ def receive_object obj
15
+ $server = obj
16
+ EM.stop
17
+ end
18
+ end
19
+
20
+ module Client
21
+ include EM::P::ObjectProtocol
22
+ def receive_object obj
23
+ $client = obj
24
+ send_object 'you_said'=>obj
25
+ end
26
+ end
27
+
28
+ def test_send_receive
29
+ EM.run{
30
+ EM.start_server Host, Port, Server
31
+ EM.connect Host, Port, Client
32
+ }
33
+
34
+ assert($client == {:hello=>'world'})
35
+ assert($server == {'you_said'=>{:hello=>'world'}})
36
+ end
37
+ end
@@ -0,0 +1,48 @@
1
+ $:.unshift "../lib"
2
+ require 'eventmachine'
3
+ require 'test/unit'
4
+
5
+ class TestProcessWatch < Test::Unit::TestCase
6
+ module ParentProcessWatcher
7
+ def process_forked
8
+ $forked = true
9
+ end
10
+ end
11
+
12
+ module ChildProcessWatcher
13
+ def process_exited
14
+ $exited = true
15
+ end
16
+ def unbind
17
+ $unbind = true
18
+ EM.stop
19
+ end
20
+ end
21
+
22
+ def setup
23
+ EM.kqueue = true if EM.kqueue?
24
+ end
25
+
26
+ def teardown
27
+ EM.kqueue = false if EM.kqueue?
28
+ end
29
+
30
+ def test_events
31
+ EM.run{
32
+ # watch ourselves for a fork notification
33
+ EM.watch_process(Process.pid, ParentProcessWatcher)
34
+ $fork_pid = fork{ sleep }
35
+ child = EM.watch_process($fork_pid, ChildProcessWatcher)
36
+ $pid = child.pid
37
+
38
+ EM.add_timer(0.5){
39
+ Process.kill('TERM', $fork_pid)
40
+ }
41
+ }
42
+
43
+ assert_equal($pid, $fork_pid)
44
+ assert($forked)
45
+ assert($exited)
46
+ assert($unbind)
47
+ end
48
+ end
@@ -1,95 +1,128 @@
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 TestProcesses < Test::Unit::TestCase
32
-
33
- # EM::DeferrableChildProcess is a sugaring of a common use-case
34
- # involving EM::popen.
35
- # Call the #open method on EM::DeferrableChildProcess, passing
36
- # a command-string. #open immediately returns an EM::Deferrable
37
- # object. It also schedules the forking of a child process, which
38
- # will execute the command passed to #open.
39
- # When the forked child terminates, the Deferrable will be signalled
40
- # and execute its callbacks, passing the data that the child process
41
- # wrote to stdout.
42
- #
43
- def test_deferrable_child_process
44
- ls = ""
45
- EM.run {
46
- d = EM::DeferrableChildProcess.open( "ls -ltr" )
47
- d.callback {|data_from_child|
48
- ls = data_from_child
49
- EM.stop
50
- }
51
- }
52
- assert( ls.length > 0)
53
- end
54
-
55
- def setup
56
- $out = nil
57
- $status = nil
58
- end
59
-
60
- def test_em_system
61
- EM.run{
62
- EM.system('ls'){ |out,status| $out, $status = out, status; EM.stop }
63
- }
64
-
65
- assert( $out.length > 0 )
66
- assert_equal($status.exitstatus, 0)
67
- assert_equal($status.class, Process::Status)
68
- end
69
-
70
- def test_em_system_with_proc
71
- EM.run{
72
- EM.system('ls', proc{ |out,status| $out, $status = out, status; EM.stop })
73
- }
74
-
75
- assert( $out.length > 0 )
76
- assert_equal($status.exitstatus, 0)
77
- assert_equal($status.class, Process::Status)
78
- end
79
-
80
- def test_em_system_with_two_procs
81
- EM.run{
82
- EM.system('sh', proc{ |process|
83
- process.send_data("echo hello\n")
84
- process.send_data("exit\n")
85
- }, proc{ |out,status|
86
- $out = out
87
- $status = status
88
- EM.stop
89
- })
90
- }
91
-
92
- assert_equal($out, "hello\n")
93
- end
94
- end
95
-
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 TestProcesses < Test::Unit::TestCase
32
+
33
+ # EM::DeferrableChildProcess is a sugaring of a common use-case
34
+ # involving EM::popen.
35
+ # Call the #open method on EM::DeferrableChildProcess, passing
36
+ # a command-string. #open immediately returns an EM::Deferrable
37
+ # object. It also schedules the forking of a child process, which
38
+ # will execute the command passed to #open.
39
+ # When the forked child terminates, the Deferrable will be signalled
40
+ # and execute its callbacks, passing the data that the child process
41
+ # wrote to stdout.
42
+ #
43
+ def test_deferrable_child_process
44
+ ls = ""
45
+ EM.run {
46
+ d = EM::DeferrableChildProcess.open( "ls -ltr" )
47
+ d.callback {|data_from_child|
48
+ ls = data_from_child
49
+ EM.stop
50
+ }
51
+ }
52
+ assert( ls.length > 0)
53
+ end
54
+
55
+ def setup
56
+ $out = nil
57
+ $status = nil
58
+ end
59
+
60
+ def test_em_system
61
+ EM.run{
62
+ EM.system('ls'){ |out,status| $out, $status = out, status; EM.stop }
63
+ }
64
+
65
+ assert( $out.length > 0 )
66
+ assert_equal($status.exitstatus, 0)
67
+ assert_equal($status.class, Process::Status)
68
+ end
69
+
70
+ def test_em_system_pid
71
+ $pids = []
72
+
73
+ EM.run{
74
+ $pids << EM.system('echo hi', proc{ |out,status|$pids << status.pid; EM.stop })
75
+ }
76
+
77
+ assert_equal $pids[0], $pids[1]
78
+ end
79
+
80
+ def test_em_system_with_proc
81
+ EM.run{
82
+ EM.system('ls', proc{ |out,status| $out, $status = out, status; EM.stop })
83
+ }
84
+
85
+ assert( $out.length > 0 )
86
+ assert_equal($status.exitstatus, 0)
87
+ assert_equal($status.class, Process::Status)
88
+ end
89
+
90
+ def test_em_system_with_two_procs
91
+ EM.run{
92
+ EM.system('sh', proc{ |process|
93
+ process.send_data("echo hello\n")
94
+ process.send_data("exit\n")
95
+ }, proc{ |out,status|
96
+ $out = out
97
+ $status = status
98
+ EM.stop
99
+ })
100
+ }
101
+
102
+ assert_equal("hello\n", $out)
103
+ end
104
+
105
+ def test_em_system_cmd_arguments
106
+ EM.run{
107
+ EM.system('sh', '--version', proc{ |process|
108
+ }, proc{ |out,status|
109
+ $out = out
110
+ $status = status
111
+ EM.stop
112
+ })
113
+ }
114
+
115
+ assert_match(/version/i, $out)
116
+ end
117
+
118
+ def test_em_system_spaced_arguments
119
+ EM.run{
120
+ EM.system('ruby', '-e', 'puts "hello"', proc{ |out,status|
121
+ $out = out
122
+ EM.stop
123
+ })
124
+ }
125
+
126
+ assert_equal("hello\n", $out)
127
+ end
128
+ end