Class: ZMachine::Channel

Inherits:
Object
  • Object
show all
Defined in:
lib/zmachine/channel.rb

Direct Known Subclasses

TCPChannel, ZMQChannel

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeChannel

Returns a new instance of Channel.



8
9
10
11
12
# File 'lib/zmachine/channel.rb', line 8

def initialize
  @inbound_buffer = ByteBuffer.allocate(1024 * 1024)
  @outbound_queue = []
  @close_scheduled = false
end

Instance Attribute Details

#socketObject

Returns the value of attribute socket.



6
7
8
# File 'lib/zmachine/channel.rb', line 6

def socket
  @socket
end

Instance Method Details

#can_send?Boolean

methods that need to be implemented in sub classes:

selectable_fd bind(address, port = nil) bound? accept connect(address, port = nil) connection_pending? finish_connecting connected? read_inbound_data send_data(data) closed? peer write_outbound_data

Returns:

  • (Boolean)


30
31
32
# File 'lib/zmachine/channel.rb', line 30

def can_send?
  !@outbound_queue.empty?
end

#close(after_writing = false) ⇒ Object



34
35
36
37
38
# File 'lib/zmachine/channel.rb', line 34

def close(after_writing = false)
  ZMachine.logger.debug("zmachine:channel:#{__method__}", channel: self, after_writing: after_writing) if ZMachine.debug
  @close_scheduled = true
  @outbound_queue.clear unless after_writing
end

#close_after_writingObject



40
41
42
# File 'lib/zmachine/channel.rb', line 40

def close_after_writing
  close(true)
end