Class: NIO::WebSocket::Adapter

Inherits:
RawAdapter show all
Defined in:
lib/nio/websocket/adapter.rb,
lib/nio/websocket/adapter/proxy.rb,
lib/nio/websocket/adapter/client.rb,
lib/nio/websocket/adapter/server.rb

Direct Known Subclasses

Client, Server

Defined Under Namespace

Classes: Client, Proxy, ProxyAdapter, Server

Instance Attribute Summary collapse

Attributes inherited from RawAdapter

#closing, #inner, #monitor, #options

Instance Method Summary collapse

Methods inherited from RawAdapter

#add_to_reactor, #pump_buffer, #write

Constructor Details

#initialize(io, driver, options) ⇒ Adapter

Returns a new instance of Adapter.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/nio/websocket/adapter.rb', line 6

def initialize(io, driver, options)
  @driver = driver

  driver.on :close do |ev|
    WebSocket.logger.info "Driver initiated #{inner} close (code #{ev.code}): #{ev.reason}"
    close :driver
  end
  driver.on :error do |ev|
    WebSocket.logger.error "Driver reports error on #{inner}: #{ev.message}"
    close :driver
  end

  super io, options
end

Instance Attribute Details

#driverObject (readonly)

Returns the value of attribute driver.



20
21
22
# File 'lib/nio/websocket/adapter.rb', line 20

def driver
  @driver
end

Instance Method Details

#close(from = nil) ⇒ Object



29
30
31
32
# File 'lib/nio/websocket/adapter.rb', line 29

def close(from = nil)
  driver.close if from.nil? && !closing
  super()
end

#readObject



34
35
36
37
38
# File 'lib/nio/websocket/adapter.rb', line 34

def read
  super do |data|
    driver.parse data
  end
end

#teardownObject



22
23
24
25
26
27
# File 'lib/nio/websocket/adapter.rb', line 22

def teardown
  driver.force_state :closed
  driver.emit :io_error
  @driver = nil # circular reference
  super
end