Changeset 203

Show
Ignore:
Timestamp:
06/14/06 19:02:33 (2 years ago)
Author:
rosejn
Message:

Starting on an example application

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • experiments/EventMachine/lib/machine/io.rb

    r202 r203  
    77 
    88module Machine 
    9   # Receives 
     9  AcceptEvent = EventType.new :host, :port 
     10  ConnectEvent = EventType.new :host, :port 
     11  CloseConnectionEvent = EventType.new :now 
     12 
    1013  SendRawDataEvent = EventType.new :data 
    11   CloseConnectionEvent = EventType.new :now 
    12  
    13   # Sends 
    1414  RecvRawDataEvent = EventType.new :data 
     15 
    1516  BindEvent = EventType.new :data 
    1617 
     
    200201 
    201202  class TCPClient < IOHandler 
    202     ConnectEvent = EventType.new :host, :port 
     203 
     204    attr_reader :dispatcher 
    203205 
    204206    # We assume we're getting a TCP socket on which 
     
    207209    # When it selects writable, the connect has completed. 
    208210    # 
    209     def initialize(dispatcher, host, port, stack = [], &block) 
    210       @dispatcher = dispatcher 
     211    def initialize(host, port, stack = [], &block) 
     212      @dispatcher = EventDispatcher.new 
    211213      @host = host 
    212214      @port = port 
     
    246248 
    247249  class TCPServer < IOHandler 
    248     AcceptEvent = EventType.new :host, :port 
    249  
    250250    LISTEN_BACKLOG_SIZE = 50 # 5 is what you see in all the books. Ain't enough. 
    251251    NIO_ACCEPT_ATTEMPTS = 10 
     252 
     253    attr_reader :dispatcher 
    252254 
    253255    #-- 
     
    261263    # Of course we'll also need named pipes and whatever that Windows 
    262264    # near-equivalent is called. 
    263     def self.initialize(dispatcher, host, port, stack = [], &block) 
     265    def initialize(host, port, stack = [], &block) 
     266      @dispatcher = EventDispatcher.new 
    264267      sd = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM, 0) 
    265268      sd.setsockopt(Socket::SOL_SOCKET, Socket::SO_REUSEADDR, true) 
     
    267270      sd.listen(LISTEN_BACKLOG_SIZE) 
    268271 
    269       super(dispatcher, sd) 
     272      super(@dispatcher, sd) 
    270273    end 
    271274 
     
    290293 
    291294      # 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 
    294298 
    295299      port, host = Socket.unpack_sockaddr_in(addr) 
    296       @dispatcher.send_event(AcceptEvent.new(host, port)) 
     300      con_dispatcher.send_event(AcceptEvent.new(host, port)) 
    297301    end 
    298302  end 
  • experiments/EventMachine/Rakefile

    r200 r203  
    2121Rake::RDocTask.new(:doc) { |rdoc| 
    2222  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') 
    2525  rdoc.rdoc_dir = 'docs/api' 
    2626  rdoc.title    = "EventMachine -- Event Based Application Framework" 
     
    4040 
    4141  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"  
    4545  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'
    4848 
    49   s.author = "Francis Cianfrocca, Jeff Rose, ???"  
     49  s.author = "Francis Cianfrocca, Jeff Rose" 
    5050  s.email = "garbagecat10@gmail.com, rosejn@gmail.com"  
    5151end  
  • experiments/EventMachine/test/io_test.rb

    r202 r203  
    3030    end 
    3131 
    32     a,b = Socket::socketpair( Socket::AF_UNIX, Socket::SOCK_STREAM, 0) 
     32    a,b = Socket::socketpair(Socket::AF_UNIX, Socket::SOCK_STREAM, 0) 
    3333    a_handler = IOHandler.new(a_dispatch, a) 
    3434    b_handler = IOHandler.new(b_dispatch, b)