eventmachine 1.0.0.beta.2-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (141) hide show
  1. data/.gitignore +16 -0
  2. data/Gemfile +1 -0
  3. data/README +81 -0
  4. data/Rakefile +11 -0
  5. data/docs/COPYING +60 -0
  6. data/docs/ChangeLog +211 -0
  7. data/docs/DEFERRABLES +246 -0
  8. data/docs/EPOLL +141 -0
  9. data/docs/GNU +281 -0
  10. data/docs/INSTALL +13 -0
  11. data/docs/KEYBOARD +42 -0
  12. data/docs/LEGAL +25 -0
  13. data/docs/LIGHTWEIGHT_CONCURRENCY +130 -0
  14. data/docs/PURE_RUBY +75 -0
  15. data/docs/RELEASE_NOTES +94 -0
  16. data/docs/SMTP +4 -0
  17. data/docs/SPAWNED_PROCESSES +148 -0
  18. data/docs/TODO +8 -0
  19. data/eventmachine.gemspec +33 -0
  20. data/examples/ex_channel.rb +43 -0
  21. data/examples/ex_queue.rb +2 -0
  22. data/examples/ex_tick_loop_array.rb +15 -0
  23. data/examples/ex_tick_loop_counter.rb +32 -0
  24. data/examples/helper.rb +2 -0
  25. data/ext/binder.cpp +124 -0
  26. data/ext/binder.h +46 -0
  27. data/ext/cmain.cpp +838 -0
  28. data/ext/ed.cpp +1884 -0
  29. data/ext/ed.h +418 -0
  30. data/ext/em.cpp +2348 -0
  31. data/ext/em.h +228 -0
  32. data/ext/eventmachine.h +123 -0
  33. data/ext/extconf.rb +157 -0
  34. data/ext/fastfilereader/extconf.rb +85 -0
  35. data/ext/fastfilereader/mapper.cpp +214 -0
  36. data/ext/fastfilereader/mapper.h +59 -0
  37. data/ext/fastfilereader/rubymain.cpp +127 -0
  38. data/ext/kb.cpp +79 -0
  39. data/ext/page.cpp +107 -0
  40. data/ext/page.h +51 -0
  41. data/ext/pipe.cpp +347 -0
  42. data/ext/project.h +155 -0
  43. data/ext/rubymain.cpp +1200 -0
  44. data/ext/ssl.cpp +460 -0
  45. data/ext/ssl.h +94 -0
  46. data/java/.classpath +8 -0
  47. data/java/.project +17 -0
  48. data/java/src/com/rubyeventmachine/EmReactor.java +571 -0
  49. data/java/src/com/rubyeventmachine/EmReactorException.java +40 -0
  50. data/java/src/com/rubyeventmachine/EventableChannel.java +69 -0
  51. data/java/src/com/rubyeventmachine/EventableDatagramChannel.java +189 -0
  52. data/java/src/com/rubyeventmachine/EventableSocketChannel.java +364 -0
  53. data/lib/em/buftok.rb +138 -0
  54. data/lib/em/callback.rb +26 -0
  55. data/lib/em/channel.rb +57 -0
  56. data/lib/em/connection.rb +569 -0
  57. data/lib/em/deferrable.rb +206 -0
  58. data/lib/em/file_watch.rb +54 -0
  59. data/lib/em/future.rb +61 -0
  60. data/lib/em/iterator.rb +270 -0
  61. data/lib/em/messages.rb +66 -0
  62. data/lib/em/process_watch.rb +44 -0
  63. data/lib/em/processes.rb +119 -0
  64. data/lib/em/protocols.rb +36 -0
  65. data/lib/em/protocols/header_and_content.rb +138 -0
  66. data/lib/em/protocols/httpclient.rb +268 -0
  67. data/lib/em/protocols/httpclient2.rb +590 -0
  68. data/lib/em/protocols/line_and_text.rb +125 -0
  69. data/lib/em/protocols/line_protocol.rb +28 -0
  70. data/lib/em/protocols/linetext2.rb +161 -0
  71. data/lib/em/protocols/memcache.rb +323 -0
  72. data/lib/em/protocols/object_protocol.rb +45 -0
  73. data/lib/em/protocols/postgres3.rb +247 -0
  74. data/lib/em/protocols/saslauth.rb +175 -0
  75. data/lib/em/protocols/smtpclient.rb +357 -0
  76. data/lib/em/protocols/smtpserver.rb +640 -0
  77. data/lib/em/protocols/socks4.rb +66 -0
  78. data/lib/em/protocols/stomp.rb +200 -0
  79. data/lib/em/protocols/tcptest.rb +53 -0
  80. data/lib/em/pure_ruby.rb +1013 -0
  81. data/lib/em/queue.rb +62 -0
  82. data/lib/em/spawnable.rb +85 -0
  83. data/lib/em/streamer.rb +130 -0
  84. data/lib/em/tick_loop.rb +85 -0
  85. data/lib/em/timers.rb +57 -0
  86. data/lib/em/version.rb +3 -0
  87. data/lib/eventmachine.rb +1548 -0
  88. data/lib/jeventmachine.rb +258 -0
  89. data/lib/rubyeventmachine.rb +2 -0
  90. data/setup.rb +1585 -0
  91. data/tasks/cpp.rake_example +77 -0
  92. data/tasks/doc.rake +30 -0
  93. data/tasks/package.rake +85 -0
  94. data/tasks/test.rake +6 -0
  95. data/tests/client.crt +31 -0
  96. data/tests/client.key +51 -0
  97. data/tests/test_attach.rb +136 -0
  98. data/tests/test_basic.rb +249 -0
  99. data/tests/test_channel.rb +64 -0
  100. data/tests/test_connection_count.rb +35 -0
  101. data/tests/test_defer.rb +49 -0
  102. data/tests/test_deferrable.rb +35 -0
  103. data/tests/test_epoll.rb +160 -0
  104. data/tests/test_error_handler.rb +35 -0
  105. data/tests/test_errors.rb +82 -0
  106. data/tests/test_exc.rb +55 -0
  107. data/tests/test_file_watch.rb +49 -0
  108. data/tests/test_futures.rb +198 -0
  109. data/tests/test_get_sock_opt.rb +30 -0
  110. data/tests/test_handler_check.rb +37 -0
  111. data/tests/test_hc.rb +190 -0
  112. data/tests/test_httpclient.rb +227 -0
  113. data/tests/test_httpclient2.rb +154 -0
  114. data/tests/test_inactivity_timeout.rb +50 -0
  115. data/tests/test_kb.rb +60 -0
  116. data/tests/test_ltp.rb +190 -0
  117. data/tests/test_ltp2.rb +317 -0
  118. data/tests/test_next_tick.rb +133 -0
  119. data/tests/test_object_protocol.rb +37 -0
  120. data/tests/test_pause.rb +70 -0
  121. data/tests/test_pending_connect_timeout.rb +48 -0
  122. data/tests/test_process_watch.rb +50 -0
  123. data/tests/test_processes.rb +128 -0
  124. data/tests/test_proxy_connection.rb +144 -0
  125. data/tests/test_pure.rb +134 -0
  126. data/tests/test_queue.rb +44 -0
  127. data/tests/test_running.rb +42 -0
  128. data/tests/test_sasl.rb +72 -0
  129. data/tests/test_send_file.rb +251 -0
  130. data/tests/test_servers.rb +76 -0
  131. data/tests/test_smtpclient.rb +83 -0
  132. data/tests/test_smtpserver.rb +85 -0
  133. data/tests/test_spawn.rb +322 -0
  134. data/tests/test_ssl_args.rb +79 -0
  135. data/tests/test_ssl_methods.rb +50 -0
  136. data/tests/test_ssl_verify.rb +82 -0
  137. data/tests/test_tick_loop.rb +59 -0
  138. data/tests/test_timers.rb +160 -0
  139. data/tests/test_ud.rb +36 -0
  140. data/tests/testem.rb +31 -0
  141. metadata +240 -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
@@ -0,0 +1,30 @@
1
+ rdoc_task_type = begin
2
+ require 'rdoc/task'
3
+ RDoc::Task
4
+ rescue LoadError
5
+ require 'rake/rdoctask'
6
+ Rake::RDocTask
7
+ end
8
+
9
+ df = begin; require 'rdoc/rdoc'; require 'rdoc/generator/darkfish'; true; rescue LoadError; end
10
+
11
+ rdtask = rdoc_task_type.new do |rd|
12
+ rd.title = GEMSPEC.name
13
+ rd.rdoc_dir = 'rdoc'
14
+ rd.main = "README"
15
+ rd.rdoc_files.include("lib/**/*.rb", *GEMSPEC.extra_rdoc_files)
16
+ rd.rdoc_files.exclude(*%w(lib/em/version lib/emva lib/evma/ lib/pr_eventmachine lib/jeventmachine))
17
+ rd.template = 'darkfish' if df
18
+ end
19
+
20
+ Rake::Task[:clean].enhance [:clobber_rdoc]
21
+
22
+ desc 'Generate and open documentation'
23
+ task :docs => :rdoc do
24
+ case RUBY_PLATFORM
25
+ when /darwin/ ; sh 'open rdoc/index.html'
26
+ when /mswin|mingw/ ; sh 'start rdoc\index.html'
27
+ else
28
+ sh 'firefox rdoc/index.html'
29
+ end
30
+ end
@@ -0,0 +1,85 @@
1
+ require 'rake/gempackagetask'
2
+ require 'rake/extensiontask'
3
+ require 'rake/javaextensiontask'
4
+
5
+ Rake::GemPackageTask.new(GEMSPEC) do |pkg|
6
+ end
7
+
8
+ if RUBY_PLATFORM =~ /java/
9
+ Rake::JavaExtensionTask.new("rubyeventmachine", GEMSPEC) do |ext|
10
+ ext.ext_dir = 'java/src'
11
+ end
12
+ else
13
+ def setup_cross_compilation(ext)
14
+ unless RUBY_PLATFORM =~ /mswin|mingw/
15
+ ext.cross_compile = true
16
+ ext.cross_platform = ['x86-mingw32', 'x86-mswin32-60']
17
+
18
+ # inject 1.8/1.9 pure-ruby entry point
19
+ ext.cross_compiling do |spec|
20
+ spec.files += ["lib/#{ext.name}.rb"]
21
+ end
22
+ end
23
+ end
24
+
25
+ Rake::ExtensionTask.new("rubyeventmachine", GEMSPEC) do |ext|
26
+ ext.ext_dir = 'ext'
27
+ setup_cross_compilation(ext)
28
+ end
29
+ Rake::ExtensionTask.new("fastfilereaderext", GEMSPEC) do |ext|
30
+ ext.ext_dir = 'ext/fastfilereader'
31
+ setup_cross_compilation(ext)
32
+ end
33
+ end
34
+
35
+ # Setup shim files that require 1.8 vs 1.9 extensions in win32 bin gems
36
+ %w[ rubyeventmachine fastfilereaderext ].each do |filename|
37
+ file("lib/#{filename}.rb") do |t|
38
+ File.open(t.name, 'wb') do |f|
39
+ f.write <<-eoruby
40
+ RUBY_VERSION =~ /(\\d+.\\d+)/
41
+ require "\#{$1}/#{File.basename(t.name, '.rb')}"
42
+ eoruby
43
+ end
44
+ at_exit{ FileUtils.rm t.name if File.exists?(t.name) }
45
+ end
46
+ end
47
+
48
+ task :cross_cxx do
49
+ ENV['CROSS_COMPILING'] = 'yes'
50
+ ENV['CXX'] = 'i386-mingw32-g++'
51
+ end
52
+
53
+ if Rake::Task.task_defined?(:cross)
54
+ task :cross => 'lib/rubyeventmachine.rb'
55
+ task :cross => 'lib/fastfilereaderext.rb'
56
+ task :cross => :cross_cxx
57
+ end
58
+
59
+ def windows?; RUBY_PLATFORM =~ /mswin|mingw/; end
60
+ def sudo(cmd)
61
+ if windows? || (require 'etc'; Etc.getpwuid.uid == 0)
62
+ sh cmd
63
+ else
64
+ sh "sudo #{cmd}"
65
+ end
66
+ end
67
+ def gem_cmd(action, name, *args)
68
+ rb = Gem.ruby rescue nil
69
+ rb ||= (require 'rbconfig'; File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name']))
70
+ sudo "#{rb} -r rubygems -e 'require %{rubygems/gem_runner}; Gem::GemRunner.new.run(%w{#{action} #{name} #{args.join(' ')}})'"
71
+ end
72
+
73
+ Rake::Task[:clean].enhance [:clobber_package]
74
+
75
+ namespace :gem do
76
+ desc 'Install gem (and sudo if required)'
77
+ task :install => :package do
78
+ gem_cmd(:install, "pkg/#{GEMSPEC.name}-#{GEMSPEC.version}.gem")
79
+ end
80
+
81
+ desc 'Uninstall gem (and sudo if required)'
82
+ task :uninstall do
83
+ gem_cmd(:uninstall, "#{GEMSPEC.name}", "-v=#{GEMSPEC.version}")
84
+ end
85
+ end
@@ -0,0 +1,6 @@
1
+ require 'rake/testtask'
2
+
3
+ Rake::TestTask.new(:test) do |t|
4
+ t.pattern = 'tests/**/test_*.rb'
5
+ t.warning = true
6
+ end
@@ -0,0 +1,31 @@
1
+ -----BEGIN CERTIFICATE-----
2
+ MIIFRDCCAywCAQEwDQYJKoZIhvcNAQEFBQAwaDELMAkGA1UEBhMCRU0xFTATBgNV
3
+ BAgTDEV2ZW50TWFjaGluZTEVMBMGA1UEChMMRXZlbnRNYWNoaW5lMRQwEgYDVQQL
4
+ EwtEZXZlbG9wbWVudDEVMBMGA1U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0RG2rQoc5CQWxxNPcBFOtIXQMkKizGvTUHUwImqeYWMZsxzASdNH2WoV
38
+ jsPbyaGfPhmcv83ZKyDp8IvtrXMZkiaT4vlm3Xi8VeKR9jY9z7/gMob1XcEDg3c9
39
+ cCkGOy87WZrXSLhX02mAJzJCycqom66gqNw7pPxjIiY/8VWUEZsTvkL3cymTkhjM
40
+ 9ZOhAoIBAGUaNqJe01NTrV+ZJgGyAxM6s8LXQYV5IvjuL2bJKxwUvvP2cT9FFGWD
41
+ qYiRrKJr5ayS07IUC+58oIzu33/0DSa27JgfduD9HrT3nKMK1mSEfRFSAjiXChQc
42
+ bIubRGapBoub/AdxMazqoovvT1R9b84kobQfcVAMV6DYh0CVZWyXYfgsV2DSVOiK
43
+ iufjfoDzg5lLCEI+1XW3/LunrB/W4yPN1X/amf8234ublYyt+2ucD4NUGnP05xLa
44
+ N6P7M0MwdEEKkvMe0YBBSFH5kWK/dIOjqkgBDes20fVnuuz/tL1dZW7IiIP4dzaV
45
+ ZGEOwBEatCfqYetv6b/u3IUxDfS7Wg8CggEBALoOwkn5LGdQg+bpdZAKJspGnJWL
46
+ Kyr9Al2tvgc69rxfpZqS5eDLkYYCzWPpspSt0Axm1O7xOUDQDt42luaLNGJzHZ2Q
47
+ Hn0ZNMhyHpe8d8mIQngRjD+nuLI/uFUglPzabDOCOln2aycjg1mA6ecXP1XMEVbu
48
+ 0RB/0IE36XTMfZ+u9+TRjkBLpmUaX1FdIQQWfwUou/LfaXotoQlhSGAcprLrncuJ
49
+ T44UATYEgO/q9pMM33bdE3eBYZHoT9mSvqoLCN4s0LuwOYItIxLKUj0GulL0VQOI
50
+ SZi+0A1c8cVDXgApkBrWPDQIR9JS4de0gW4hnDoUvHtUc2TYPRnz6N9MtFY=
51
+ -----END RSA PRIVATE KEY-----
@@ -0,0 +1,136 @@
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.1){ EM.stop }
50
+ end
51
+ end
52
+ end
53
+
54
+ def setup
55
+ $read, $write, $sock, $r, $w, $fd, $sock, $before, $after = nil
56
+ end
57
+
58
+ def teardown
59
+ [$read, $write, $sock, $r, $w, $fd, $sock, $before, $after].each do |io|
60
+ io.close rescue nil
61
+ end
62
+ end
63
+
64
+ def test_attach
65
+ EM.run{
66
+ EM.start_server Host, Port, EchoServer
67
+ $sock = TCPSocket.new Host, Port
68
+ EM.watch $sock, EchoClient
69
+ }
70
+
71
+ assert_equal $read, "abc\n"
72
+ unless defined? JRuby # jruby filenos are not real
73
+ assert_equal $fd, $sock.fileno
74
+ end
75
+ assert_equal false, $sock.closed?
76
+ assert_equal $sock.readline, "def\n"
77
+ end
78
+
79
+ module PipeWatch
80
+ def notify_readable
81
+ $read = $r.readline
82
+ EM.stop
83
+ end
84
+ end
85
+
86
+ def test_attach_pipe
87
+ EM.run{
88
+ $r, $w = IO.pipe
89
+ EM.watch $r, PipeWatch do |c|
90
+ c.notify_readable = true
91
+ end
92
+ $w.write("ghi\n")
93
+ }
94
+
95
+ assert_equal $read, "ghi\n"
96
+ end
97
+
98
+ def test_set_readable
99
+ EM.run{
100
+ $r, $w = IO.pipe
101
+ c = EM.watch $r, PipeWatch do |con|
102
+ con.notify_readable = false
103
+ end
104
+
105
+ EM.next_tick{
106
+ $before = c.notify_readable?
107
+ c.notify_readable = true
108
+ $after = c.notify_readable?
109
+ }
110
+
111
+ $w.write("jkl\n")
112
+ }
113
+
114
+ assert !$before
115
+ assert $after
116
+ assert_equal $read, "jkl\n"
117
+ end
118
+
119
+ module PipeReader
120
+ def receive_data data
121
+ $read = data
122
+ EM.stop
123
+ end
124
+ end
125
+
126
+ def test_read_write_pipe
127
+ EM.run{
128
+ $r, $w = IO.pipe
129
+ EM.attach $r, PipeReader
130
+ writer = EM.attach($w)
131
+ writer.send_data 'ghi'
132
+ }
133
+
134
+ assert_equal $read, "ghi"
135
+ end
136
+ end
@@ -0,0 +1,249 @@
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
+ def test_connection_class_cache
34
+ mod = Module.new
35
+ a, b = nil, nil
36
+ EM.run {
37
+ EM.start_server '127.0.0.1', 9999, mod
38
+ a = EM.connect '127.0.0.1', 9999, mod
39
+ b = EM.connect '127.0.0.1', 9999, mod
40
+ EM.stop
41
+ }
42
+ assert_equal a.class, b.class
43
+ assert_kind_of EM::Connection, a
44
+ end
45
+
46
+ #-------------------------------------
47
+
48
+
49
+ def test_em
50
+ EventMachine.run {
51
+ EventMachine.add_timer 0 do
52
+ EventMachine.stop
53
+ end
54
+ }
55
+ end
56
+
57
+ #-------------------------------------
58
+
59
+ def test_timer
60
+ n = 0
61
+ EventMachine.run {
62
+ EventMachine.add_periodic_timer(0.1) {
63
+ n += 1
64
+ EventMachine.stop if n == 2
65
+ }
66
+ }
67
+ end
68
+
69
+ #-------------------------------------
70
+
71
+ # This test once threw an already-running exception.
72
+ module Trivial
73
+ def post_init
74
+ EventMachine.stop
75
+ end
76
+ end
77
+
78
+ def test_server
79
+ EventMachine.run {
80
+ EventMachine.start_server "localhost", 9000, Trivial
81
+ EventMachine.connect "localhost", 9000
82
+ }
83
+ assert( true ) # make sure it halts
84
+ end
85
+
86
+ #--------------------------------------
87
+
88
+ # EventMachine#run_block starts the reactor loop, runs the supplied block, and then STOPS
89
+ # the loop automatically. Contrast with EventMachine#run, which keeps running the reactor
90
+ # even after the supplied block completes.
91
+ def test_run_block
92
+ assert !EM.reactor_running?
93
+ a = nil
94
+ EM.run_block { a = "Worked" }
95
+ assert a
96
+ assert !EM.reactor_running?
97
+ end
98
+
99
+ TestHost = "127.0.0.1"
100
+ TestPort = 9070
101
+
102
+ class UnbindError < EM::Connection
103
+ ERR = Class.new(StandardError)
104
+ def initialize *args
105
+ super
106
+ end
107
+ def connection_completed
108
+ close_connection_after_writing
109
+ end
110
+ def unbind
111
+ raise ERR
112
+ end
113
+ end
114
+
115
+ def test_unbind_error
116
+ assert_raises( UnbindError::ERR ) {
117
+ EM.run {
118
+ EM.start_server TestHost, TestPort
119
+ EM.connect TestHost, TestPort, UnbindError
120
+ }
121
+ }
122
+ end
123
+
124
+ module BrsTestSrv
125
+ def receive_data data
126
+ $received << data
127
+ end
128
+ def unbind
129
+ EM.stop
130
+ end
131
+ end
132
+ module BrsTestCli
133
+ def post_init
134
+ send_data $sent
135
+ close_connection_after_writing
136
+ end
137
+ end
138
+
139
+ def setup_timeout(timeout = 4)
140
+ EM.schedule {
141
+ start_time = EM.current_time
142
+ EM.add_periodic_timer(0.01) {
143
+ raise "timeout" if EM.current_time - start_time >= timeout
144
+ }
145
+ }
146
+ end
147
+
148
+ # From ticket #50
149
+ def test_byte_range_send
150
+ $received = ''
151
+ $sent = (0..255).to_a.pack('C*')
152
+ EM::run {
153
+ EM::start_server TestHost, TestPort, BrsTestSrv
154
+ EM::connect TestHost, TestPort, BrsTestCli
155
+
156
+ setup_timeout
157
+ }
158
+ assert_equal($sent, $received)
159
+ end
160
+
161
+ def test_bind_connect
162
+ local_ip = UDPSocket.open {|s| s.connect('google.com', 80); s.addr.last }
163
+
164
+ bind_port = rand(33333)+1025
165
+
166
+ test = self
167
+ EM.run do
168
+ EM.start_server(TestHost, TestPort, Module.new do
169
+ define_method :post_init do
170
+ begin
171
+ test.assert_equal bind_port, Socket.unpack_sockaddr_in(get_peername).first
172
+ test.assert_equal local_ip, Socket.unpack_sockaddr_in(get_peername).last
173
+ ensure
174
+ EM.stop_event_loop
175
+ end
176
+ end
177
+ end)
178
+ EM.bind_connect local_ip, bind_port, TestHost, TestPort
179
+ end
180
+ end
181
+
182
+ def test_reactor_thread?
183
+ assert !EM.reactor_thread?
184
+ EM.run { assert EM.reactor_thread?; EM.stop }
185
+ assert !EM.reactor_thread?
186
+ end
187
+
188
+ def test_schedule_on_reactor_thread
189
+ x = false
190
+ EM.run do
191
+ EM.schedule { x = true }
192
+ EM.stop
193
+ end
194
+ assert x
195
+ end
196
+
197
+ def test_schedule_from_thread
198
+ x = false
199
+ assert !x
200
+ EM.run do
201
+ Thread.new { EM.schedule { x = true; EM.stop } }.join
202
+ end
203
+ assert x
204
+ end
205
+
206
+ def test_set_heartbeat_interval
207
+ interval = 0.5
208
+ EM.run {
209
+ EM.set_heartbeat_interval interval
210
+ $interval = EM.get_heartbeat_interval
211
+ EM.stop
212
+ }
213
+ assert_equal(interval, $interval)
214
+ end
215
+
216
+ module PostInitRaiser
217
+ ERR = Class.new(StandardError)
218
+ def post_init
219
+ raise ERR
220
+ end
221
+ end
222
+
223
+ def test_bubble_errors_from_post_init
224
+ localhost, port = '127.0.0.1', 9000
225
+ assert_raises(PostInitRaiser::ERR) do
226
+ EM.run do
227
+ EM.start_server localhost, port
228
+ EM.connect localhost, port, PostInitRaiser
229
+ end
230
+ end
231
+ end
232
+
233
+ module InitializeRaiser
234
+ ERR = Class.new(StandardError)
235
+ def initialize
236
+ raise ERR
237
+ end
238
+ end
239
+
240
+ def test_bubble_errors_from_initialize
241
+ localhost, port = '127.0.0.1', 9000
242
+ assert_raises(InitializeRaiser::ERR) do
243
+ EM.run do
244
+ EM.start_server localhost, port
245
+ EM.connect localhost, port, InitializeRaiser
246
+ end
247
+ end
248
+ end
249
+ end