Class: Foolio::Handler

Inherits:
Object
  • Object
show all
Includes:
Listener
Defined in:
lib/foolio/stream.rb

Direct Known Subclasses

BlockHandler

Instance Method Summary collapse

Methods included from Listener

#callback

Constructor Details

#initialize(handle) ⇒ Handler

Returns a new instance of Handler.



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

def initialize(handle)
  @handle = handle
end

Instance Method Details

#closeObject



16
17
18
19
20
21
# File 'lib/foolio/stream.rb', line 16

def close
  $log.info "close #{@handle}"
  Foolio::UV.close(@handle, callback{
                     clear_callbacks
                   })
end

#on_closeObject



25
# File 'lib/foolio/stream.rb', line 25

def on_close; end

#on_connectObject



24
# File 'lib/foolio/stream.rb', line 24

def on_connect; end

#on_recv(data) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/foolio/stream.rb', line 27

def on_recv(data)
  if data then
    on_read(data)
  else
    close
  end
end

#on_write_complete(err) ⇒ Object



23
# File 'lib/foolio/stream.rb', line 23

def on_write_complete(err); end

#startObject



35
36
37
# File 'lib/foolio/stream.rb', line 35

def start
  Foolio::UV.read_start(@handle, callback(&method(:on_recv)))
end

#write(data) ⇒ Object



11
12
13
14
# File 'lib/foolio/stream.rb', line 11

def write(data)
  Foolio::UV.write(nil, @handle, data, callback{|status|
                     on_write_complete(status)})
end