Changeset 203
- Timestamp:
- 06/14/06 19:02:33 (2 years ago)
- Files:
-
- experiments/EventMachine/examples (added)
- experiments/EventMachine/examples/cmd.rb (added)
- experiments/EventMachine/examples/p2p.rb (added)
- experiments/EventMachine/GPL (added)
- experiments/EventMachine/lib/machine/io.rb (modified) (7 diffs)
- experiments/EventMachine/LICENSE (added)
- experiments/EventMachine/Rakefile (modified) (2 diffs)
- experiments/EventMachine/README (added)
- experiments/EventMachine/test/io_test.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
experiments/EventMachine/lib/machine/io.rb
r202 r203 7 7 8 8 module Machine 9 # Receives 9 AcceptEvent = EventType.new :host, :port 10 ConnectEvent = EventType.new :host, :port 11 CloseConnectionEvent = EventType.new :now 12 10 13 SendRawDataEvent = EventType.new :data 11 CloseConnectionEvent = EventType.new :now12 13 # Sends14 14 RecvRawDataEvent = EventType.new :data 15 15 16 BindEvent = EventType.new :data 16 17 … … 200 201 201 202 class TCPClient < IOHandler 202 ConnectEvent = EventType.new :host, :port 203 204 attr_reader :dispatcher 203 205 204 206 # We assume we're getting a TCP socket on which … … 207 209 # When it selects writable, the connect has completed. 208 210 # 209 def initialize( dispatcher,host, port, stack = [], &block)210 @dispatcher = dispatcher211 def initialize(host, port, stack = [], &block) 212 @dispatcher = EventDispatcher.new 211 213 @host = host 212 214 @port = port … … 246 248 247 249 class TCPServer < IOHandler 248 AcceptEvent = EventType.new :host, :port249 250 250 LISTEN_BACKLOG_SIZE = 50 # 5 is what you see in all the books. Ain't enough. 251 251 NIO_ACCEPT_ATTEMPTS = 10 252 253 attr_reader :dispatcher 252 254 253 255 #-- … … 261 263 # Of course we'll also need named pipes and whatever that Windows 262 264 # near-equivalent is called. 263 def self.initialize(dispatcher, host, port, stack = [], &block) 265 def initialize(host, port, stack = [], &block) 266 @dispatcher = EventDispatcher.new 264 267 sd = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM, 0) 265 268 sd.setsockopt(Socket::SOL_SOCKET, Socket::SO_REUSEADDR, true) … … 267 270 sd.listen(LISTEN_BACKLOG_SIZE) 268 271 269 super( dispatcher, sd)272 super(@dispatcher, sd) 270 273 end 271 274 … … 290 293 291 294 # Now we build the stack on top of the new socket. 292 stack.each {|proto| proto.new(dispatcher)} 293 block.call(dispatcher) if block 295 con_dispatcher = EventDispatcher.new 296 stack.each {|proto| proto.new(con_dispatcher)} 297 block.call(con_dispatcher) if block 294 298 295 299 port, host = Socket.unpack_sockaddr_in(addr) 296 @dispatcher.send_event(AcceptEvent.new(host, port))300 con_dispatcher.send_event(AcceptEvent.new(host, port)) 297 301 end 298 302 end experiments/EventMachine/Rakefile
r200 r203 21 21 Rake::RDocTask.new(:doc) { |rdoc| 22 22 rdoc.main = 'README' 23 rdoc.rdoc_files.include('lib/**/*.rb', 'README' )24 rdoc.rdoc_files.include('GPL', 'COPYING')23 rdoc.rdoc_files.include('lib/**/*.rb', 'README', 'LICENSE', 'GPL', 'TODO', 24 'Credits', 'ChangeLog') 25 25 rdoc.rdoc_dir = 'docs/api' 26 26 rdoc.title = "EventMachine -- Event Based Application Framework" … … 40 40 41 41 s.files = FileList["{test,lib,docs}/**/*"].to_a 42 s.files += [ "Rakefile", "README", "COPYING", "GPL" ]43 s.require_path = "lib"44 s.autorequire = " eventmachine"42 s.files += ['GPL', 'LICENSE', 'README', 'Rakefile', 43 'ChangeLog', 'Credits', 'TODO'] 44 s.autorequire = "machine" 45 45 s.has_rdoc = true 46 s.extra_rdoc_files = ["README", " COPYING", "GPL"]47 s.rdoc_options.concat ['--main', 'README' ]46 s.extra_rdoc_files = ["README", "GPL"] 47 s.rdoc_options.concat ['--main', 'README', '--line-numbers'] 48 48 49 s.author = "Francis Cianfrocca, Jeff Rose , ???"49 s.author = "Francis Cianfrocca, Jeff Rose" 50 50 s.email = "garbagecat10@gmail.com, rosejn@gmail.com" 51 51 end experiments/EventMachine/test/io_test.rb
r202 r203 30 30 end 31 31 32 a,b = Socket::socketpair( 32 a,b = Socket::socketpair(Socket::AF_UNIX, Socket::SOCK_STREAM, 0) 33 33 a_handler = IOHandler.new(a_dispatch, a) 34 34 b_handler = IOHandler.new(b_dispatch, b)