Changeset 148

Show
Ignore:
Timestamp:
05/26/06 19:22:55 (2 years ago)
Author:
blackhedd
Message:

Added convenience class method start_server.

Files:

Legend:

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

    r143 r148  
    229229 
    230230  #-- 
     231  # sugar over starting a TCP server. 
     232  # INCOMPLETE, will throw a bunch of different socket-library 
     233  # errors (DNS, no-bind, etc) which we ought to wrap and 
     234  # either re-raise, or generate events for. 
     235  # INCOMPLETE, need to similarly sugar creation of Unix-domain sockets. 
     236  # Either a different method, or observe the params: for unix 
     237  # only a filename is needed. 
     238  # Of course we'll also need named pipes and whatever that Windows 
     239  # near-equivalent is called. 
     240  # RETURNS: the newly-created eventable-io object, so the caller 
     241  # can add handlers, etc. 
     242  # 
     243  def self.start_server host, port 
     244    sd = Socket.new( Socket::AF_INET, Socket::SOCK_STREAM, 0 ) 
     245    sd.bind( Socket.pack_sockaddr_in( port, host )) 
     246    sd.listen( 50 ) # 5 is what you see in all the books. Ain't enough. 
     247    TcpServerEventableIO.new sd 
     248  end 
     249 
     250  #-- 
    231251  # Ruby accept_nonblock is applied on class Socket, 
    232252  # but for some unknown reason, TCPServer is not a 
     
    237257  # sd.bind( Socket.pack_sockaddr_in( port, server )) 
    238258  # sd.listen(5) 
    239   # eio = TCPServerEventableIO.new( sd ) 
     259  # eio = TcpServerEventableIO.new( sd ) 
    240260  # 
    241261  # For Unix-domain sockets, the idiom is: 
     
    243263  # sd.bind( Socket.pack_sockaddr_un( socketname )) 
    244264  # sd.listen(5) 
    245   # eio = TCPServerEventableIO.new( sd ) 
     265  # eio = TcpServerEventableIO.new( sd ) 
    246266  # 
    247267  #