Class: Toycol::Server
- Inherits:
-
Object
- Object
- Toycol::Server
- Defined in:
- lib/toycol/server.rb
Constant Summary collapse
- BACKLOG =
1024
- CHUNK_SIZE =
1024 * 16
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(app, **options) ⇒ Server
constructor
A new instance of Server.
- #run ⇒ Object
Constructor Details
#initialize(app, **options) ⇒ Server
Returns a new instance of Server.
14 15 16 17 18 19 20 21 22 |
# File 'lib/toycol/server.rb', line 14 def initialize(app, **) @app = app @path = [:Path] @port = [:Port] @env = default_env @returned_status = nil @returned_headers = nil @returned_body = nil end |
Class Method Details
.run(app, **options) ⇒ Object
9 10 11 |
# File 'lib/toycol/server.rb', line 9 def run(app, **) new(app, **).run end |
Instance Method Details
#run ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/toycol/server.rb', line 24 def run verify_file_path! server = UNIXServer.new @path server.listen BACKLOG loop do trap(:INT) { exit } socket = server.accept = [] << socket.readpartial(CHUNK_SIZE) until socket.eof? = .join assign_parsed_attributes!() @returned_status, @returned_headers, @returned_body = @app.call(@env) socket.puts socket.close_write socket.close end end |