Class: Gazouillis::Stream

Inherits:
Object
  • Object
show all
Includes:
Celluloid::IO
Defined in:
lib/gazouillis/stream.rb

Overview

This class concern is to handle stream connections.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, opts) ⇒ Stream

Returns a new instance of Stream.



9
10
11
12
13
14
15
16
# File 'lib/gazouillis/stream.rb', line 9

def initialize(path, opts)
  options = default_options.merge(opts)
  @request = Request.new(path, options)
  @stream = set_stream(TCPSocket.new options[:host], options[:port])
  @http_parser = Http::Parser.new
  http_parser.on_body = on_message_callback
  http_parser.on_headers_complete = on_headers_complete
end

Instance Attribute Details

#http_parserObject (readonly)

Returns the value of attribute http_parser.



7
8
9
# File 'lib/gazouillis/stream.rb', line 7

def http_parser
  @http_parser
end

#requestObject (readonly)

Returns the value of attribute request.



7
8
9
# File 'lib/gazouillis/stream.rb', line 7

def request
  @request
end

#streamObject (readonly)

Returns the value of attribute stream.



7
8
9
# File 'lib/gazouillis/stream.rb', line 7

def stream
  @stream
end

Instance Method Details

#closeObject



23
24
25
# File 'lib/gazouillis/stream.rb', line 23

def close
  stream.to_io.close
end

#on_message(message) ⇒ Object



27
28
29
# File 'lib/gazouillis/stream.rb', line 27

def on_message(message)
  # Hook method. To be override.
end

#openObject



18
19
20
21
# File 'lib/gazouillis/stream.rb', line 18

def open
  stream.write request
  handle_connection
end