libc-eventmachine 0.12.5.42

Sign up to get free protection for your applications and to get access to all the features.
Files changed (131) hide show
  1. data/Rakefile +195 -0
  2. data/docs/COPYING +60 -0
  3. data/docs/ChangeLog +211 -0
  4. data/docs/DEFERRABLES +138 -0
  5. data/docs/EPOLL +141 -0
  6. data/docs/GNU +281 -0
  7. data/docs/INSTALL +15 -0
  8. data/docs/KEYBOARD +38 -0
  9. data/docs/LEGAL +25 -0
  10. data/docs/LIGHTWEIGHT_CONCURRENCY +72 -0
  11. data/docs/PURE_RUBY +77 -0
  12. data/docs/README +74 -0
  13. data/docs/RELEASE_NOTES +96 -0
  14. data/docs/SMTP +9 -0
  15. data/docs/SPAWNED_PROCESSES +93 -0
  16. data/docs/TODO +10 -0
  17. data/ext/binder.cpp +126 -0
  18. data/ext/binder.h +48 -0
  19. data/ext/cmain.cpp +582 -0
  20. data/ext/cplusplus.cpp +177 -0
  21. data/ext/ed.cpp +1522 -0
  22. data/ext/ed.h +380 -0
  23. data/ext/em.cpp +1947 -0
  24. data/ext/em.h +186 -0
  25. data/ext/emwin.cpp +300 -0
  26. data/ext/emwin.h +94 -0
  27. data/ext/epoll.cpp +26 -0
  28. data/ext/epoll.h +25 -0
  29. data/ext/eventmachine.h +98 -0
  30. data/ext/eventmachine_cpp.h +96 -0
  31. data/ext/extconf.rb +129 -0
  32. data/ext/fastfilereader/extconf.rb +77 -0
  33. data/ext/fastfilereader/mapper.cpp +214 -0
  34. data/ext/fastfilereader/mapper.h +59 -0
  35. data/ext/fastfilereader/rubymain.cpp +127 -0
  36. data/ext/files.cpp +94 -0
  37. data/ext/files.h +65 -0
  38. data/ext/kb.cpp +82 -0
  39. data/ext/page.cpp +107 -0
  40. data/ext/page.h +51 -0
  41. data/ext/pipe.cpp +351 -0
  42. data/ext/project.h +119 -0
  43. data/ext/rubymain.cpp +858 -0
  44. data/ext/sigs.cpp +89 -0
  45. data/ext/sigs.h +32 -0
  46. data/ext/ssl.cpp +423 -0
  47. data/ext/ssl.h +90 -0
  48. data/java/src/com/rubyeventmachine/Application.java +196 -0
  49. data/java/src/com/rubyeventmachine/Connection.java +74 -0
  50. data/java/src/com/rubyeventmachine/ConnectionFactory.java +37 -0
  51. data/java/src/com/rubyeventmachine/DefaultConnectionFactory.java +46 -0
  52. data/java/src/com/rubyeventmachine/EmReactor.java +408 -0
  53. data/java/src/com/rubyeventmachine/EmReactorException.java +40 -0
  54. data/java/src/com/rubyeventmachine/EventableChannel.java +57 -0
  55. data/java/src/com/rubyeventmachine/EventableDatagramChannel.java +171 -0
  56. data/java/src/com/rubyeventmachine/EventableSocketChannel.java +244 -0
  57. data/java/src/com/rubyeventmachine/PeriodicTimer.java +38 -0
  58. data/java/src/com/rubyeventmachine/Timer.java +54 -0
  59. data/java/src/com/rubyeventmachine/tests/ApplicationTest.java +108 -0
  60. data/java/src/com/rubyeventmachine/tests/ConnectTest.java +124 -0
  61. data/java/src/com/rubyeventmachine/tests/EMTest.java +80 -0
  62. data/java/src/com/rubyeventmachine/tests/TestDatagrams.java +53 -0
  63. data/java/src/com/rubyeventmachine/tests/TestServers.java +74 -0
  64. data/java/src/com/rubyeventmachine/tests/TestTimers.java +89 -0
  65. data/lib/em/deferrable.rb +208 -0
  66. data/lib/em/eventable.rb +39 -0
  67. data/lib/em/future.rb +62 -0
  68. data/lib/em/messages.rb +66 -0
  69. data/lib/em/processes.rb +68 -0
  70. data/lib/em/spawnable.rb +88 -0
  71. data/lib/em/streamer.rb +112 -0
  72. data/lib/eventmachine.rb +1920 -0
  73. data/lib/eventmachine_version.rb +31 -0
  74. data/lib/evma/callback.rb +32 -0
  75. data/lib/evma/container.rb +75 -0
  76. data/lib/evma/factory.rb +77 -0
  77. data/lib/evma/protocol.rb +87 -0
  78. data/lib/evma/reactor.rb +48 -0
  79. data/lib/evma.rb +32 -0
  80. data/lib/jeventmachine.rb +140 -0
  81. data/lib/pr_eventmachine.rb +1017 -0
  82. data/lib/protocols/buftok.rb +127 -0
  83. data/lib/protocols/header_and_content.rb +129 -0
  84. data/lib/protocols/httpcli2.rb +803 -0
  85. data/lib/protocols/httpclient.rb +270 -0
  86. data/lib/protocols/line_and_text.rb +126 -0
  87. data/lib/protocols/linetext2.rb +161 -0
  88. data/lib/protocols/memcache.rb +293 -0
  89. data/lib/protocols/postgres.rb +261 -0
  90. data/lib/protocols/saslauth.rb +179 -0
  91. data/lib/protocols/smtpclient.rb +308 -0
  92. data/lib/protocols/smtpserver.rb +556 -0
  93. data/lib/protocols/stomp.rb +153 -0
  94. data/lib/protocols/tcptest.rb +57 -0
  95. data/tasks/cpp.rake +77 -0
  96. data/tasks/project.rake +78 -0
  97. data/tasks/tests.rake +193 -0
  98. data/tests/test_attach.rb +83 -0
  99. data/tests/test_basic.rb +231 -0
  100. data/tests/test_bind.rb +73 -0
  101. data/tests/test_connection_count.rb +35 -0
  102. data/tests/test_defer.rb +47 -0
  103. data/tests/test_epoll.rb +163 -0
  104. data/tests/test_error_handler.rb +32 -0
  105. data/tests/test_errors.rb +82 -0
  106. data/tests/test_eventables.rb +77 -0
  107. data/tests/test_exc.rb +58 -0
  108. data/tests/test_futures.rb +214 -0
  109. data/tests/test_handler_check.rb +37 -0
  110. data/tests/test_hc.rb +218 -0
  111. data/tests/test_httpclient.rb +215 -0
  112. data/tests/test_httpclient2.rb +155 -0
  113. data/tests/test_kb.rb +61 -0
  114. data/tests/test_ltp.rb +188 -0
  115. data/tests/test_ltp2.rb +320 -0
  116. data/tests/test_next_tick.rb +109 -0
  117. data/tests/test_processes.rb +56 -0
  118. data/tests/test_pure.rb +129 -0
  119. data/tests/test_running.rb +47 -0
  120. data/tests/test_sasl.rb +74 -0
  121. data/tests/test_send_file.rb +243 -0
  122. data/tests/test_servers.rb +80 -0
  123. data/tests/test_smtpclient.rb +83 -0
  124. data/tests/test_smtpserver.rb +93 -0
  125. data/tests/test_spawn.rb +329 -0
  126. data/tests/test_ssl_args.rb +68 -0
  127. data/tests/test_ssl_methods.rb +50 -0
  128. data/tests/test_timers.rb +148 -0
  129. data/tests/test_ud.rb +43 -0
  130. data/tests/testem.rb +31 -0
  131. metadata +230 -0
data/Rakefile ADDED
@@ -0,0 +1,195 @@
1
+ #!/usr/bin/env rake
2
+ #--
3
+ # Ruby/EventMachine
4
+ # http://rubyeventmachine.com
5
+ # Copyright (C) 2006-07 by Francis Cianfrocca
6
+ #
7
+ # This program is copyrighted free software. You may use it under
8
+ # the terms of either the GPL or Ruby's License. See the file
9
+ # COPYING in the EventMachine distribution for full licensing
10
+ # information.
11
+ #
12
+ # $Id$
13
+ #++
14
+
15
+ ### OLD RAKE: ###
16
+ # # The tasks and external gemspecs we used to generate binary gems are now
17
+ # # obsolete. Use Patrick Hurley's gembuilder to build binary gems for any
18
+ # # desired platform.
19
+ # # To build a binary gem on Win32, ensure that the include and lib paths
20
+ # # both contain the proper references to OPENSSL. Use the static version
21
+ # # of the libraries, not the dynamic, otherwise we expose the user to a
22
+ # # runtime dependency.
23
+ #
24
+ # # To build a binary gem for win32, first build rubyeventmachine.so
25
+ # # using VC6 outside of the build tree (the normal way: ruby extconf.rb,
26
+ # # and then nmake). Then copy rubyeventmachine.so into the lib directory,
27
+ # # and run rake gemwin32.
28
+ #
29
+
30
+ require 'rubygems' unless defined?(Gem)
31
+ require 'rake' unless defined?(Rake)
32
+ require 'rake/gempackagetask'
33
+
34
+ Package = false # Build zips and tarballs?
35
+ Dir.glob('tasks/*.rake').each { |r| Rake.application.add_import r }
36
+
37
+ # e.g. rake EVENTMACHINE_LIBRARY=java for forcing java build tasks as defaults!
38
+ $eventmachine_library = :java if RUBY_PLATFORM =~ /java/ || ENV['EVENTMACHINE_LIBRARY'] == 'java'
39
+ $eventmachine_library = :pure_ruby if ENV['EVENTMACHINE_LIBRARY'] == 'pure_ruby'
40
+
41
+ MAKE = ENV['MAKE'] || if RUBY_PLATFORM =~ /mswin/ # mingw uses make.
42
+ 'nmake'
43
+ else
44
+ 'make'
45
+ end
46
+
47
+ # If running under rubygems...
48
+ __DIR__ ||= File.expand_path(File.dirname(__FILE__))
49
+ if Gem.path.map{|path| Dir.chdir(path){ Dir.pwd } rescue path }.any? {|path| %r(^#{Regexp.escape path}) =~ __DIR__}
50
+ task :default => :gem_build
51
+ else
52
+ desc "Build gemspec, then build eventmachine, then run tests."
53
+ task :default => [:build, :test]
54
+ end
55
+
56
+ desc ":default build when running under rubygems."
57
+ task :gem_build => :build
58
+
59
+ desc "Build extension (or EVENTMACHINE_LIBRARY) and place in lib"
60
+ build_task = 'ext:build'
61
+ build_task = 'java:build' if $eventmachine_library == :java
62
+ build_task = :dummy_build if $eventmachine_library == :pure_ruby
63
+ task :build => build_task do |t|
64
+ Dir.glob('{ext,java/src,ext/fastfilereader}/*.{so,bundle,dll,jar}').each do |f|
65
+ mv f, "lib"
66
+ end
67
+ end
68
+
69
+ task :dummy_build
70
+
71
+ # Basic clean definition, this is enhanced by imports aswell.
72
+ task :clean do
73
+ chdir 'ext' do
74
+ sh "#{MAKE} clean" if test ?e, 'Makefile'
75
+ end
76
+ chdir 'ext/fastfilereader' do
77
+ sh "#{MAKE} clean" if test ?e, 'Makefile'
78
+ end
79
+ Dir.glob('**/Makefile').each { |file| rm file }
80
+ Dir.glob('**/*.{o,so,bundle,class,jar,dll,log}').each { |file| rm file }
81
+ Dir.glob('ext/**/conftest.dSYM').each{ |file| rm_rf file }
82
+ end
83
+
84
+ Spec = Gem::Specification.new do |s|
85
+ s.name = "eventmachine"
86
+ s.summary = "Ruby/EventMachine library"
87
+ s.platform = Gem::Platform::RUBY
88
+
89
+ s.has_rdoc = true
90
+ s.rdoc_options = %w(--title EventMachine --main docs/README --line-numbers)
91
+ s.extra_rdoc_files = Dir['docs/*']
92
+
93
+ s.files = %w(Rakefile) + Dir["{bin,tests,lib,ext,java,tasks}/**/*"]
94
+
95
+ s.require_path = 'lib'
96
+
97
+ # TODO / XXX - should we enable this? rubygems fails the install if anything
98
+ # is broken. What we could do is CI submission, though, and always terminate
99
+ # with a positive code...
100
+ # s.test_file = "tests/testem.rb"
101
+
102
+ # XXX Using rake to compile extensions breaks when you have multiple ruby installations
103
+ # and your path isn't set. We can switch back to this once the Gem.exec patch is merged.
104
+ # s.extensions = "Rakefile"
105
+ s.extensions = ["ext/extconf.rb", "ext/fastfilereader/extconf.rb"]
106
+
107
+ s.author = "Francis Cianfrocca"
108
+ s.email = "garbagecat10@gmail.com"
109
+ s.rubyforge_project = 'eventmachine'
110
+ s.homepage = "http://rubyeventmachine.com"
111
+
112
+ # Pulled in from readme, as code to pull from readme was not working!
113
+ # Might be worth removing as no one seems to use gem info anyway.
114
+ s.description = <<-EOD
115
+ EventMachine implements a fast, single-threaded engine for arbitrary network
116
+ communications. It's extremely easy to use in Ruby. EventMachine wraps all
117
+ interactions with IP sockets, allowing programs to concentrate on the
118
+ implementation of network protocols. It can be used to create both network
119
+ servers and clients. To create a server or client, a Ruby program only needs
120
+ to specify the IP address and port, and provide a Module that implements the
121
+ communications protocol. Implementations of several standard network protocols
122
+ are provided with the package, primarily to serve as examples. The real goal
123
+ of EventMachine is to enable programs to easily interface with other programs
124
+ using TCP/IP, especially if custom protocols are required.
125
+ EOD
126
+
127
+ require 'lib/eventmachine_version'
128
+ s.version = EventMachine::VERSION
129
+ end
130
+
131
+ namespace :ext do
132
+ ext_sources = FileList['ext/*.{h,cpp,rb,c}']
133
+ ffr_sources = FileList['ext/fastfilereader/*.{h,cpp,rb}']
134
+
135
+ desc "Build C++ extension"
136
+ task :build => [:make]
137
+
138
+ desc "make extensions"
139
+ task :make => ext_sources + ['ext/Makefile'] do
140
+ chdir 'ext' do
141
+ sh MAKE
142
+ end
143
+ end
144
+ task :make => ffr_sources + ['ext/fastfilereader/Makefile'] do
145
+ chdir 'ext/fastfilereader' do
146
+ sh MAKE
147
+ end
148
+ end
149
+
150
+ desc 'Compile the makefile'
151
+ file 'ext/Makefile' => ext_sources do
152
+ chdir 'ext' do
153
+ ruby 'extconf.rb'
154
+ end
155
+ end
156
+
157
+ desc 'Compile fastfilereader makefile'
158
+ file 'ext/fastfilereader/Makefile' => ffr_sources do
159
+ chdir 'ext/fastfilereader' do
160
+ ruby 'extconf.rb'
161
+ end
162
+ end
163
+ end
164
+
165
+ namespace :java do
166
+ # This task creates the JRuby JAR file and leaves it in the lib directory.
167
+ # This step is required before executing the jgem task.
168
+ desc "Build java extension"
169
+ task :build => [:jar] do |t|
170
+ chdir('java/src') do
171
+ mv 'em_reactor.jar', '../../lib/em_reactor.jar'
172
+ end
173
+ end
174
+
175
+ desc "compile .java to .class"
176
+ task :compile do
177
+ chdir('java/src') do
178
+ sh 'javac com/rubyeventmachine/*.java'
179
+ end
180
+ end
181
+
182
+ desc "compile .classes to .jar"
183
+ task :jar => [:compile] do
184
+ chdir('java/src') do
185
+ sh "jar -cf em_reactor.jar com/rubyeventmachine/*.class"
186
+ end
187
+ end
188
+ end
189
+
190
+ task :gemspec => :clobber do
191
+ open("eventmachine.gemspec", 'w') { |f| f.write Spec.to_ruby }
192
+ end
193
+
194
+ task :clobber => :clean
195
+ task :test => :build
data/docs/COPYING ADDED
@@ -0,0 +1,60 @@
1
+ EventMachine is copyrighted free software owned by Francis Cianfrocca
2
+ (blackhedd ... gmail.com). The Owner of this software permits you to
3
+ redistribute and/or modify the software under either the terms of the GPL
4
+ version 2 (see the file GPL), or the conditions below ("Ruby License"):
5
+
6
+ 1. You may make and give away verbatim copies of the source form of this
7
+ software without restriction, provided that you retain ALL of the
8
+ original copyright notices and associated disclaimers.
9
+
10
+ 2. You may modify your copy of the software in any way, provided that
11
+ you do at least ONE of the following:
12
+
13
+ a) place your modifications in the Public Domain or otherwise
14
+ make them Freely Available, such as by posting said
15
+ modifications to Usenet or an equivalent medium, or by allowing
16
+ the author to include your modifications in the software.
17
+
18
+ b) use the modified software only within your corporation or
19
+ organization.
20
+
21
+ c) give non-standard binaries non-standard names, with
22
+ instructions on where to get the original software distribution.
23
+
24
+ d) make other distribution arrangements with the Owner.
25
+
26
+ 3. You may distribute the software in object code or binary form,
27
+ provided that you do at least ONE of the following:
28
+
29
+ a) distribute the binaries and library files of the software,
30
+ together with instructions (in a manual page or equivalent)
31
+ on where to get the original distribution.
32
+
33
+ b) accompany the distribution with the machine-readable source of
34
+ the software.
35
+
36
+ c) give non-standard binaries non-standard names, with
37
+ instructions on where to get the original software distribution.
38
+
39
+ d) make other distribution arrangements with the Owner.
40
+
41
+ 4. You may modify and include parts of the software into any other
42
+ software (possibly commercial), provided you comply with the terms in
43
+ Sections 1, 2, and 3 above. But some files in the distribution
44
+ are not written by the Owner, so they may be made available to you
45
+ under different terms.
46
+
47
+ For the list of those files and their copying conditions, see the
48
+ file LEGAL.
49
+
50
+ 5. The scripts and library files supplied as input to or produced as
51
+ output from the software do not automatically fall under the
52
+ copyright of the software, but belong to whoever generated them,
53
+ and may be sold commercially, and may be aggregated with this
54
+ software.
55
+
56
+ 6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
57
+ IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
58
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
59
+ PURPOSE.
60
+
data/docs/ChangeLog ADDED
@@ -0,0 +1,211 @@
1
+ 01Oct06: Replaced EventMachine#open_datagram_server with a version that can
2
+ take a Class or a Module, instead of just a Module. Thanks to Tobias
3
+ Gustafsson for pointing out the missing case.
4
+ 04Oct06: Supported subsecond timer resolutions, per request by Jason Roelofs.
5
+ 05Oct06: Added EventMachine#set_quantum, which sets the timer resolution.
6
+ 15Nov06: Added Connection#set_comm_inactivity_timeout.
7
+ 15Nov06: Checked in a Line-and-Text Protocol Handler.
8
+ 18Nov06: Checked in a Header-and-Body Protocol Handler.
9
+ 22Nov06: Changed EventMachine#reconnect: no longer excepts when called on an
10
+ already-connected handler.
11
+ 28Nov06: Supported a binary-unix gem.
12
+ 19Dec06: Added EventMachine#set_effective_user.
13
+ 05Jan07: Upped max outstanding timers to 1000.
14
+ 15May07: Applied Solaris patches from Brett Eisenberg
15
+ 22May07: Cleaned up the license text in all the source files.
16
+ 22May07: Released version 0.7.2
17
+
18
+ 23May07: Per suggestion from Bill Kelly, fixed a bug with the initialization
19
+ of the network libraries under Windows. The goal is to enable EM to
20
+ be used without Ruby.
21
+ 28May07: Applied patch from Bill Kelly, refactors the declarations of
22
+ event names to make EM easier to use from C programs without Ruby.
23
+ 31May07: Added a preliminary implementation of EventMachine#popen.
24
+ 01Jun07: Added EM, a "pseudo-alias" for EventMachine.
25
+ 01Jun07: Added EM#next_tick.
26
+ 01Jun07: Added EM::Connection#get_outbound_data_size
27
+ 05Jun07: Removed the code which loads a pure-Ruby EM library in case the
28
+ compiled extension is unavailable. Suggested by Moshe Litvin.
29
+ 06Jun07: Preliminary epoll implementation.
30
+ 12Jun07: Added an evented popen implementation that, like Ruby's, is
31
+ full-duplex and makes the subprocess PID available to the caller.
32
+ 06Jul07: Performance-tweaked the callback dispatcher in eventmachine.rb.
33
+ 10Jul07: Released version 0.8.0.
34
+ 12Jul07: Applied patches from Tim Pease to fix Solaris build problems.
35
+ 15Jul07: Created a new provisional source branch, experiments/jruby-1.
36
+ This is a preliminary implementation of the EM reactor in Java,
37
+ suitable for use with JRuby.
38
+ 17Jul07: Added EventMachine#stop_server, per request from Kirk Haines,
39
+ and associated unit tests.
40
+ 22Jul07: Added EventMachine#stream_file_data. This is a very fast and scalable
41
+ way of sending data from static files over network connections. It
42
+ has separate implementations for small files and large file, and
43
+ has tunings to minimize memory consumption.
44
+ 26Jul07: Added some patches by Kirk Haines to improve the behavior of
45
+ EM::Connection#send_file_data_to_connection.
46
+ 26Jul07: Added a C++ module for directly integrating EM into C++ programs
47
+ with no Ruby dependencies. Needs example code.
48
+ 29Jul07: Added EventMachine::Protocols::LineText2.
49
+ 29Jul07: Added EventMachine::Protocols::Stomp.
50
+ 30Jul07: Added sys/stat.h to project.h to fix compilation bug on Darwin.
51
+ 13Aug07: Added EventMachine#reactor_running?
52
+ 15Aug07: Added parameters for EventMachine::Connection:start_tls that can be
53
+ used to specify client-side private keys and certificates.
54
+ 17Aug07: Added EventMachine#run_block, a sugaring for a common use case.
55
+ 24Aug07: Added a preliminary keyboard handler. Needs docs and testing on
56
+ windows.
57
+ 26Aug07: Created EventMachine::Spawnable, an implementation of Erlang-like
58
+ processes.
59
+ 27Aug07: Silenced some -w warnings, requested by James Edward Gray II.
60
+ 30Aug07: Added cookies to EM::HttpClient#request.
61
+ 04Sep07: Added an initial implementation of an evented SMTP client.
62
+ 04Sep07: Added an initial implementation of an evented SMTP server.
63
+ 10Sep07: Changed EM#spawn to run spawned blocks in the context of the
64
+ SpawnedProcess object, not of whatever was the active object at the
65
+ time of the spawn.
66
+ 14Sep07: Heartbeats weren't working with EPOLL. Noticed by Brian Candler.
67
+ 15Sep07: Added some features, tests and documents to Deferrable.
68
+ 16Sep07: Added [:content] parameter to EM::Protocols::SmtpClient#send.
69
+ 16Sep07: Bumped version to 0.9.0 in anticipation of a release.
70
+ 18Sep07: Released version 0.9.0.
71
+ 19Sep07: Added #receive_reset to EM::Protocols::SmtpServer.
72
+ 19Sep07: User overrides of EM::Protocols::SmtpServer#receive_recipient can now
73
+ return a Deferrable. Also fixed bug: SmtpClient now raises a protocol
74
+ error if none of its RCPT TO: commands are accepted by the server.
75
+ 26Sep07: Fixed missing keyboard support for Windows.
76
+ 03Oct07: Added a default handler for RuntimeErrors emitted from user-written
77
+ code. Suggested by Brian Candler.
78
+ 19Oct07: Set the SO_BROADCAST option automatically on all UDP sockets.
79
+ 10Nov07: Forced integer conversion of send_datagram's port parameter.
80
+ Suggested by Matthieu Riou.
81
+ 12Nov07: Added saslauth.rb, a protocol module to replace the Cyrus SASL
82
+ daemons saslauthd and pwcheck.
83
+ 15Nov07: Fixed bug reported by Mark Zvillius. We were failing to dispatch
84
+ zero-length datagrams under certain conditions.
85
+ 19Nov07: Added EventMachine#set_max_timers. Requested by Matthieu Riou and
86
+ others.
87
+ 19Nov07: Fixed bug with EM::Connection#start_tls. Was not working with server
88
+ connections. Reported by Michael S. Fischer.
89
+ 26Nov07: Supported a hack for EventMachine#popen so it can return an exit
90
+ status from subprocesses. Requested by Michael S. Fischer.
91
+ 30Nov07: Changed Pipe descriptors so that the child-side of the socketpair is
92
+ NOT set nonblocking. Suggested by Duane Johnson.
93
+ 05Dec07: Re-enabled the pure-Ruby implementation.
94
+ 06Dec07: Released Version 0.10.0.
95
+ 13Dec07: Added EM::DeferrableChildProcess
96
+ 24Dec07: Added a SASL client for simple password authentication.
97
+ 27Dec07: Removed the hookable error handler. No one was using it and it significantly
98
+ degraded performance.
99
+ 30Dec07: Implemented Kqueue support for OSX and BSD.
100
+ 04Jan08: Fixed bug in epoll ("Bad file descriptor"), patch supplied by Chris
101
+ Heath.
102
+ 04Jan08: Fixed bug reported by Michael S. Fischer. We were terminating
103
+ SSL connections that sent data before the handshake was complete.
104
+ 08Jan08: Added an OpenBSD branch for extconf.rb, contributed by Guillaume
105
+ Sellier.
106
+ 19Jan08: Added EM::Connection::get_sockname per request by Michael Fischer.
107
+ 19Jan08: Supported IPv6 addresses.
108
+ 30Apr08: Set the NODELAY option on sockets that we connect to other servers.
109
+ Omission noted by Roger Pack.
110
+ 14May08: Generated a 0.12 release.
111
+ 15May08: Supported EM#get_sockname for acceptors (TCP server sockets).
112
+ Requested by Roger Pack.
113
+ 15May08; Accepted a patch from Dan Aquino that allows the interval of a
114
+ PeriodicTimer to be changed on the fly.
115
+ 15Jun08: Supported nested calls to EM#run. Many people contributed ideas to
116
+ this, notably raggi and tmm1.
117
+ 20Jul08: Accepted patch from tmm1 for EM#fork_reactor.
118
+ 28Jul08: Added a Postgres3 implementation, written by FCianfrocca.
119
+ 14Aug08: Added a patch by Mike Murphy to support basic auth in the http
120
+ client.
121
+ 28Aug08: Added a patch by tmm1 to fix a longstanding problem with Java
122
+ data-sends.
123
+ 13Sep08: Added LineText2#set_binary_mode, a back-compatibility alias.
124
+ 13Sep08: Modified the load order of protocol libraries in eventmachine.rb
125
+ to permit a modification of HeaderAndContentProtocol.
126
+ 13Sep08: Modified HeaderAndContent to use LineText2, which is less buggy
127
+ than LineAndTextProtocol. This change may be reversed if we can fix
128
+ the bugs in buftok.
129
+ 13Sep08: Improved the password handling in the Postgres protocol handler.
130
+ 15Sep08: Added attach/detach, contributed by Aman Gupta (tmm1) and Riham Aldakkak,
131
+ to support working with file descriptors not created in the reactor.
132
+ 16Sep08: Added an optional version string to the HTTP client. This is a hack
133
+ that allows a client to specify a version 1.0 request, which
134
+ keeps the server from sending a chunked response. The right way to
135
+ solve this, of course, is to support chunked responses.
136
+ 23Sep08: ChangeLog Summary for Merge of branches/raggi
137
+ Most notable work and patches by Aman Gupta, Roger Pack, and James Tucker.
138
+ Patches / Tickets also submitted by: Jeremy Evans, aanand, darix, mmmurf,
139
+ danielaquino, macournoyer.
140
+ - Moved docs into docs/ dir
141
+ - Major refactor of rakefile, added generic rakefile helpers in tasks
142
+ - Added example CPP build rakefile in tasks/cpp.rake
143
+ - Moved rake tests out to tasks/tests.rake
144
+ - Added svn ignores where appropriate
145
+ - Fixed jruby build on older java platforms
146
+ - Gem now builds from Rakefile rather than directly via extconf
147
+ - Gem unified for jruby, C++ and pure ruby.
148
+ - Correction for pure C++ build, removing ruby dependency
149
+ - Fix for CYGWIN builds on ipv6
150
+ - Major refactor for extconf.rb
151
+ - Working mingw builds
152
+ - extconf optionally uses pkg_config over manual configuration
153
+ - extconf builds for 1.9 on any system that has 1.9
154
+ - extconf no longer links pthread explicitly
155
+ - looks for kqueue on all *nix systems
156
+ - better error output on std::runtime_error, now says where it came from
157
+ - Fixed some tests on jruby
158
+ - Added test for general send_data flaw, required for a bugfix in jruby build
159
+ - Added timeout to epoll tests
160
+ - Added fixes for java reactor ruby api
161
+ - Small addition of some docs in httpclient.rb and httpcli2.rb
162
+ - Some refactor and fixes in smtpserver.rb
163
+ - Added parenthesis where possible to avoid excess ruby warnings
164
+ - Refactor of $eventmachine_library logic for accuracy and maintenance, jruby
165
+ - EM::start_server now supports unix sockets
166
+ - EM::connect now supports unix sockets
167
+ - EM::defer @threadqueue now handled more gracefully
168
+ - Added better messages on exceptions raised
169
+ - Fix edge case in timer fires
170
+ - Explicitly require buftok.rb
171
+ - Add protocols to autoload, rather than require them all immediately
172
+ - Fix a bug in pr_eventmachine for outbound_q
173
+ - Refactors to take some of the use of defer out of tests.
174
+ - Fixes in EM.defer under start/stop conditions. Reduced scope of threads.
175
+ 23Sep08: Added patch from tmm1 to avoid popen errors on exit.
176
+ 30Sep08: Added File.exists? checks in the args for start_tls, as suggested by
177
+ Brian Lopez (brianmario).
178
+ 10Nov08: ruby 1.9 compatibility enhancements
179
+ 28Nov08: Allow for older ruby builds where RARRAY_LEN is not defined
180
+ 03Dec08: allow passing arguments to popen handlers
181
+ 13Jan09: SSL support for httpclient2 (David Smalley)
182
+ 22Jan09: Fixed errors on OSX with the kqueue reactor, fixed errors in the pure
183
+ ruby reactor. Added EM.current_time. Added EM.epoll? and EM.kqueue?
184
+ 27Jan09: Reactor errors are now raised as ruby RuntimeErrors.
185
+ 28Jan09: Documentation patch from alloy
186
+ 29Jan09: (Late sign-off) Use a longer timeout for connect_server (Ilya
187
+ Grigorik)
188
+ 07Feb09: Fix signal handling issues with threads+epoll
189
+ 07Feb09: Use rb_thread_schedule in the epoll reactor
190
+ 07Feb09: Use TRAP_BEG/END and rb_thread_schedule in kqueue reactor
191
+ 08Feb09: Added fastfilereader from swiftiply
192
+ 08Feb09: 1.9 fix for rb_trap_immediate
193
+ 08Feb09: Enable rb_thread_blocking_region for 1.9.0 and 1.9.1
194
+ 10Feb09: Support win32 builds for fastfilereader
195
+ 10Feb09: Added a new event to indicate completion of SSL handshake on TCP
196
+ connections
197
+ 10Feb09: Working get_peer_cert method. Returns the certificate as a Ruby
198
+ String in PEM format. (Jake Douglas)
199
+ 10Feb09: Added EM.get_max_timers
200
+ 11Feb09: Fix compile options for sun compiler (Alasdairrr)
201
+ 11Feb09: get_status returns a Process::Status object
202
+ 12Feb09: Add EM::Protocols::Memcache with simple get/set functionality
203
+ 19Feb09: Add catch-all EM.error_handler
204
+ 20Feb09: Support miniunit (1.9)
205
+ 20Feb09: Return success on content-length = 0 instead of start waiting forever
206
+ (Ugo Riboni)
207
+ 25Feb09: Allow next_tick to be used to pre-schedule reactor operations before
208
+ EM.run
209
+ 26Feb09: Added EM.get_connection_count
210
+ 01Mar09: Switch back to extconf for compiling gem extensions
211
+ 01Mar09: fixed a small bug with basic auth (mmmurf)
data/docs/DEFERRABLES ADDED
@@ -0,0 +1,138 @@
1
+ $Id$
2
+
3
+ [DOCUMENT UNDER CONSTRUCTION]
4
+
5
+ EventMachine (EM) adds two different formalisms for lightweight concurrency to the Ruby programmer's toolbox: spawned processes and deferrables. This note will show you how to use deferrables. For more information, see the separate document LIGHTWEIGHT_CONCURRENCY.
6
+
7
+
8
+ === What are Deferrables?
9
+
10
+ EventMachine's Deferrable borrows heavily from the "deferred" object in Python's "Twisted" event-handling framework. Here's a minimal example that illustrates Deferrable:
11
+
12
+ require 'eventmachine'
13
+
14
+ class MyClass
15
+ include EM::Deferrable
16
+
17
+ def print_value x
18
+ puts "MyClass instance received #{x}"
19
+ end
20
+ end
21
+
22
+ EM.run {
23
+ df = MyClass.new
24
+ df.callback {|x|
25
+ df.print_value(x)
26
+ EM.stop
27
+ }
28
+
29
+ EM::Timer.new(2) {
30
+ df.set_deferred_status :succeeded, 100
31
+ }
32
+ }
33
+
34
+
35
+ This program will spin for two seconds, print out the string "MyClass instance received 100" and then exit. The Deferrable pattern relies on an unusual metaphor that may be unfamiliar to you, unless you've used Python's Twisted. You may need to read the following material through more than once before you get the idea.
36
+
37
+ EventMachine::Deferrable is simply a Ruby Module that you can include in your own classes. (There also is a class named EventMachine::DefaultDeferrable for when you want to create one without including it in code of your own.)
38
+
39
+ An object that includes EventMachine::Deferrable is like any other Ruby object: it can be created whenever you want, returned from your functions, or passed as an argument to other functions.
40
+
41
+ The Deferrable pattern allows you to specify any number of Ruby code blocks (callbacks or errbacks) that will be executed at some future time when the status of the Deferrable object changes.
42
+
43
+ How might that be useful? Well, imagine that you're implementing an HTTP server, but you need to make a call to some other server in order to fulfill a client request.
44
+
45
+ When you receive a request from one of your clients, you can create and return a Deferrable object. Some other section of your program can add a callback to the Deferrable that will cause the client's request to be fulfilled. Simultaneously, you initiate an event-driven or threaded client request to some different server. And then your EM program will continue to process other events and service other client requests.
46
+
47
+ When your client request to the other server completes some time later, you will call the #set_deferred_status method on the Deferrable object, passing either a success or failure status, and an arbitrary number of parameters (which might include the data you received from the other server).
48
+
49
+ At that point, the status of the Deferrable object becomes known, and its callback or errback methods are immediately executed. Callbacks and errbacks are code blocks that are attached to Deferrable objects at any time through the methods #callback and #errback.
50
+
51
+ The deep beauty of this pattern is that it decouples the disposition of one operation (such as a client request to an outboard server) from the subsequent operations that depend on that disposition (which may include responding to a different client or any other operation).
52
+
53
+ The code which invokes the deferred operation (that will eventually result in a success or failure status together with associated data) is completely separate from the code which depends on that status and data. This achieves one of the primary goals for which threading is typically used in sophisticated applications, with none of the nondeterminacy or debugging difficulties of threads.
54
+
55
+ As soon as the deferred status of a Deferrable becomes known by way of a call to #set_deferred_status, the Deferrable will IMMEDIATELY execute all of its callbacks or errbacks in the order in which they were added to the Deferrable.
56
+
57
+ Callbacks and errbacks can be added to a Deferrable object at any time, not just when the object is created. They can even be added after the status of the object has been determined! (In this case, they will be executed immediately when they are added.)
58
+
59
+ A call to Deferrable#set_deferred_status takes :succeeded or :failed as its first argument. (This determines whether the object will call its callbacks or its errbacks.) #set_deferred_status also takes zero or more additional parameters, that will in turn be passed as parameters to the callbacks or errbacks.
60
+
61
+ In general, you can only call #set_deferred_status ONCE on a Deferrable object. A call to #set_deferred_status will not return until all of the associated callbacks or errbacks have been called. If you add callbacks or errbacks AFTER making a call to #set_deferred_status, those additional callbacks or errbacks will execute IMMEDIATELY. Any given callback or errback will be executed AT MOST once.
62
+
63
+ It's possible to call #set_deferred_status AGAIN, during the execution a callback or errback. This makes it possible to change the parameters which will be sent to the callbacks or errbacks farther down the chain, enabling some extremely elegant use-cases. You can transform the data returned from a deferred operation in arbitrary ways as needed by subsequent users, without changing any of the code that generated the original data.
64
+
65
+ A call to #set_deferred_status will not return until all of the associated callbacks or errbacks have been called. If you add callbacks or errbacks AFTER making a call to #set_deferred_status, those additional callbacks or errbacks will execute IMMEDIATELY.
66
+
67
+ Let's look at some more sample code. It turns out that many of the internal protocol implementations in the EventMachine package rely on Deferrable. One of these is EM::Protocols::HttpClient.
68
+
69
+ To make an evented HTTP request, use the module function EM::Protocols::HttpClient#request, which returns a Deferrable object. Here's how:
70
+
71
+ require 'eventmachine'
72
+
73
+ EM.run {
74
+ df = EM::Protocols::HttpClient.request( :host=>"www.example.com", :request=>"/index.html" )
75
+
76
+ df.callback {|response|
77
+ puts "Succeeded: #{response[:content]}"
78
+ EM.stop
79
+ }
80
+
81
+ df.errback {|response|
82
+ puts "ERROR: #{response[:status]}"
83
+ EM.stop
84
+ }
85
+ }
86
+
87
+ (See the documentation of EventMachine::Protocols::HttpClient for information on the object returned by #request.)
88
+
89
+ In this code, we make a call to HttpClient#request, which immediately returns a Deferrable object. In the background, an HTTP client request is being made to www.example.com, although your code will continue to run concurrently.
90
+
91
+ At some future point, the HTTP client request will complete, and the code in EM::Protocols::HttpClient will process either a valid HTTP response (including returned content), or an error.
92
+
93
+ At that point, EM::Protocols::HttpClient will call EM::Deferrable#set_deferred_status on the Deferrable object that was returned to your program, as the return value from EM::Protocols::HttpClient.request. You don't have to do anything to make this happen. All you have to do is tell the Deferrable what to do in case of either success, failure, or both.
94
+
95
+ In our code sample, we set one callback and one errback. The former will be called if the HTTP call succeeds, and the latter if it fails. (For simplicity, we have both of them calling EM#stop to end the program, although real programs would be very unlikely to do this.)
96
+
97
+ Setting callbacks and errbacks is optional. They are handlers to defined events in the lifecycle of the Deferrable event. It's not an error if you fail to set either a callback, an errback, or both. But of course your program will then fail to receive those notifications.
98
+
99
+ If through some bug it turns out that #set_deferred_status is never called on a Deferrable object, then that object's callbacks or errbacks will NEVER be called. It's also possible to set a timeout on a Deferrable. If the timeout elapses before any other call to #set_deferred_status, the Deferrable object will behave as is you had called set_deferred_status(:failed) on it.
100
+
101
+
102
+ Now let's modify the example to illustrate some additional points:
103
+
104
+ require 'eventmachine'
105
+
106
+ EM.run {
107
+ df = EM::Protocols::HttpClient.request( :host=>"www.example.com", :request=>"/index.html" )
108
+
109
+ df.callback {|response|
110
+ df.set_deferred_status :succeeded, response[:content]
111
+ }
112
+
113
+ df.callback {|string|
114
+ puts "Succeeded: #{string}"
115
+ EM.stop
116
+ }
117
+
118
+ df.errback {|response|
119
+ puts "ERROR: #{response[:status]}"
120
+ EM.stop
121
+ }
122
+ }
123
+
124
+
125
+ Just for the sake of illustration, we've now set two callbacks instead of one. If the deferrable operation (the HTTP client-request) succeeds, then both of the callbacks will be executed in order.
126
+
127
+ But notice that we've also made our own call to #set_deferred_status in the first callback. This isn't required, because the HttpClient implementation already made a call to #set_deferred_status. (Otherwise, of course, the callback would not be executing.)
128
+
129
+ But we used #set_deferred_status in the first callback in order to change the parameters that will be sent to subsequent callbacks in the chain. In this way, you can construct powerful sequences of layered functionality. If you want, you can even change the status of the Deferrable from :succeeded to :failed, which would abort the chain of callback calls, and invoke the chain of errbacks instead.
130
+
131
+ Now of course it's somewhat trivial to define two callbacks in the same method, even with the parameter-changing effect we just described. It would be much more interesting to pass the Deferrable to some other function (for example, a function defined in another module or a different gem), that would in turn add callbacks and/or errbacks of its own. That would illustrate the true power of the Deferrable pattern: to isolate the HTTP client-request from other functions that use the data that it returns without caring where those data came from.
132
+
133
+ Remember that you can add a callback or an errback to a Deferrable at any point in time, regardless of whether the status of the deferred operation is known (more precisely, regardless of when #set_deferred_status is called on the object). Even hours or days later.
134
+
135
+ When you add a callback or errback to a Deferrable object on which #set_deferred_status has not yet been called, the callback/errback is queued up for future execution, inside the Deferrable object. When you add a callback or errback to a Deferrable on which #set_deferred_status has already been called, the callback/errback will be executed immediately. Your code doesn't have to worry about the ordering, and there are no timing issues, as there would be with a threaded approach.
136
+
137
+ For more information on Deferrables and their typical usage patterns, look in the EM unit tests. There are also quite a few sugarings (including EM::Deferrable#future) that make typical Deferrable usages syntactically easier to work with.
138
+