diff options
author | Kazuki Yamaguchi <k@rhe.jp> | 2015-10-25 18:42:07 +0900 |
---|---|---|
committer | Kazuki Yamaguchi <k@rhe.jp> | 2015-10-25 18:42:07 +0900 |
commit | 4d5d63bc80e13b0449799f721df768bff2088c44 (patch) | |
tree | 2a4700481745e18a53b1126ee36f155d11b30cd1 /lib/plum/http_connection.rb | |
parent | 28a3a72007b2592ff5ea6bbd6984340133636065 (diff) | |
download | plum-4d5d63bc80e13b0449799f721df768bff2088c44.tar.gz |
!connection: Connection keep only writer proc
Diffstat (limited to 'lib/plum/http_connection.rb')
-rw-r--r-- | lib/plum/http_connection.rb | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/lib/plum/http_connection.rb b/lib/plum/http_connection.rb index 61445af..1ec1a6a 100644 --- a/lib/plum/http_connection.rb +++ b/lib/plum/http_connection.rb @@ -2,12 +2,27 @@ using Plum::BinaryString module Plum class HTTPConnection < Connection - def initialize(io, local_settings = {}) + attr_reader :sock + + def initialize(sock, local_settings = {}) require "http/parser" - super @_headers = nil @_body = "" @_http_parser = setup_parser + @sock = sock + super(@sock.method(:write), local_settings) + end + + # Starts communication with the peer. It blocks until the io is closed, or reaches EOF. + def run + while !@sock.closed? && !@sock.eof? + self << @sock.readpartial(1024) + end + end + + def close + super + @sock.close end private @@ -56,7 +71,7 @@ module Plum resp << "Server: plum/#{Plum::VERSION}\r\n" resp << "\r\n" - io.write(resp) + @sock.write(resp) end def process_first_request |