Included Modules

Listen::Adapter::TCP

Adapter to receive file system modifications over TCP

Constants

DEFAULTS
OS_REGEXP
RECEIVE_WINDOW

Number of bytes to receive at a time

Attributes

buffer[R]
socket[R]

Public Class Methods

local_fs?() click to toggle source
# File lib/listen/adapter/tcp.rb, line 78
def self.local_fs?
  false
end

Public Instance Methods

finalize() click to toggle source

Cleans up buffer and socket

# File lib/listen/adapter/tcp.rb, line 42
def finalize
  @buffer = nil
  return unless @socket

  @socket.close
  @socket = nil
end
handle_data(data) click to toggle source

Buffers incoming data and handles messages accordingly

# File lib/listen/adapter/tcp.rb, line 61
def handle_data(data)
  @buffer << data
  while (message = Listen::TCP::Message.from_buffer(@buffer))
    handle_message(message)
  end
rescue
  _log :error, "TCP.handle_data crashed: #{$!}:#{$@.join("\n")}"
  raise
end
handle_message(message) click to toggle source

Handles incoming message by notifying of path changes

# File lib/listen/adapter/tcp.rb, line 72
def handle_message(message)
  type, change, dir, path, _ = message.object
  _log :debug, "TCP message: #{[type, change, dir, path].inspect}"
  _queue_change(type.to_sym, Pathname(dir), path, change: change.to_sym)
end
run() click to toggle source

Continuously receive and asynchronously handle data

# File lib/listen/adapter/tcp.rb, line 54
def run
  while (data = @socket.recv(RECEIVE_WINDOW))
    async.handle_data(data)
  end
end
start() click to toggle source

Initializes and starts a Celluloid::IO-powered TCP-recipient

# File lib/listen/adapter/tcp.rb, line 22
def start
  attempts = 3
  @socket = TCPSocket.new(options.host, options.port)
  @buffer = ''
  async.run
rescue Celluloid::Task::TerminatedError
  _log :debug, "TCP adapter was terminated: #{$!.inspect}"
rescue Errno::ECONNREFUSED
  sleep 1
  attempts -= 1
  _log :warn, "TCP.start: #{$!.inspect}"
  retry if retries > 0
  _log :error, "TCP.start: #{$!.inspect}:#{$@.join("\n")}"
  raise
rescue
  _log :error, "TCP.start: #{$!.inspect}:#{$@.join("\n")}"
  raise
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.