Class: TP2::Server
- Inherits:
-
Object
- Object
- TP2::Server
- Defined in:
- lib/tp2/server.rb
Instance Method Summary collapse
-
#initialize(machine, hostname, port, &app) ⇒ Server
constructor
A new instance of Server.
- #run ⇒ Object
- #setup ⇒ Object
Constructor Details
#initialize(machine, hostname, port, &app) ⇒ Server
Returns a new instance of Server.
8 9 10 11 12 13 |
# File 'lib/tp2/server.rb', line 8 def initialize(machine, hostname, port, &app) @machine = machine @hostname = hostname @port = port @app = app end |
Instance Method Details
#run ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/tp2/server.rb', line 25 def run setup @machine.accept_each(@server_fd) do |fd| conn = HTTP1Connection.new(@machine, fd, @bgid, &@app) @machine.spin(conn) { it.run } end end |
#setup ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/tp2/server.rb', line 15 def setup @server_fd = @machine.socket(UM::AF_INET, UM::SOCK_STREAM, 0, 0) @machine.setsockopt(@server_fd, UM::SOL_SOCKET, UM::SO_REUSEADDR, true) @machine.bind(@server_fd, @hostname, @port) @machine.listen(@server_fd, UM::SOMAXCONN) @bgid = @machine.setup_buffer_ring(4096, 1024) puts "Listening on #{@hostname}:#{@port}" end |