Module: IOMultiplex::Mixins::IOReactor::Write

Included in:
IOReactor
Defined in:
lib/iomultiplex/mixins/ioreactor/write.rb

Overview

Write mixin for IOReactor

Constant Summary collapse

WRITE_BUFFER_MAX =

TODO: Make these customisable?

16_384
WRITE_SIZE =
4_096

Instance Method Summary collapse

Instance Method Details

#handle_writeObject



26
27
28
29
30
31
32
33
34
# File 'lib/iomultiplex/mixins/ioreactor/write.rb', line 26

def handle_write
  begin
    do_write
  rescue IOError, Errno::ECONNRESET => e
    write_exception e
  end

  nil
end

#write(data) ⇒ Object

Raises:

  • (IOError)


36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/iomultiplex/mixins/ioreactor/write.rb', line 36

def write(data)
  raise 'Socket is not attached' unless @attached
  raise IOError, 'Socket is closed' if @io.closed?

  @write_buffer.push data
  handle_write if @write_immediately

  # Write buffer too large - pause read polling
  if @r && write_full?
    log_debug 'write buffer full, pausing read',
              count: @write_buffer.length
    @multiplexer.stop_read self
    @multiplexer.remove_post self
  end
  nil
end

#write_full?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/iomultiplex/mixins/ioreactor/write.rb', line 53

def write_full?
  @write_buffer.length >= WRITE_BUFFER_MAX
end