Class: Listen::Adapter::TCP
- Includes:
- Celluloid::IO
- Defined in:
- lib/listen/adapter/tcp.rb
Overview
Adapter to receive file system modifications over TCP
Constant Summary collapse
- RECEIVE_WINDOW =
Number of bytes to receive at a time
1024
Constants inherited from Base
Instance Attribute Summary collapse
-
#buffer ⇒ Object
readonly
Returns the value of attribute buffer.
-
#socket ⇒ Object
readonly
Returns the value of attribute socket.
Attributes inherited from Base
Class Method Summary collapse
Instance Method Summary collapse
-
#finalize ⇒ Object
Cleans up buffer and socket.
-
#handle_data(data) ⇒ Object
Buffers incoming data and handles messages accordingly.
-
#handle_message(message) ⇒ Object
Handles incoming message by notifying of path changes.
-
#run ⇒ Object
Continuously receive and asynchronously handle data.
-
#start ⇒ Object
Initializes and starts a Celluloid::IO-powered TCP-recipient.
Methods inherited from Base
#_directories_path, #_latency, #_notify_change, #initialize
Constructor Details
This class inherits a constructor from Listen::Adapter::Base
Instance Attribute Details
#buffer ⇒ Object (readonly)
Returns the value of attribute buffer.
12 13 14 |
# File 'lib/listen/adapter/tcp.rb', line 12 def buffer @buffer end |
#socket ⇒ Object (readonly)
Returns the value of attribute socket.
12 13 14 |
# File 'lib/listen/adapter/tcp.rb', line 12 def socket @socket end |
Class Method Details
.usable? ⇒ Boolean
14 15 16 |
# File 'lib/listen/adapter/tcp.rb', line 14 def self.usable? true end |
Instance Method Details
#finalize ⇒ Object
Cleans up buffer and socket
26 27 28 29 30 31 32 |
# File 'lib/listen/adapter/tcp.rb', line 26 def finalize @buffer = nil if @socket @socket.close @socket = nil end end |
#handle_data(data) ⇒ Object
Buffers incoming data and handles messages accordingly
45 46 47 48 49 50 |
# File 'lib/listen/adapter/tcp.rb', line 45 def handle_data(data) @buffer << data while = Listen::TCP::Message.from_buffer(@buffer) () end end |
#handle_message(message) ⇒ Object
Handles incoming message by notifying of path changes
53 54 55 56 57 58 59 |
# File 'lib/listen/adapter/tcp.rb', line 53 def () .object.each do |change, paths| paths.each do |path| _notify_change(path, change: change.to_sym) end end end |
#run ⇒ Object
Continuously receive and asynchronously handle data
38 39 40 41 42 |
# File 'lib/listen/adapter/tcp.rb', line 38 def run while data = @socket.recv(RECEIVE_WINDOW) async.handle_data(data) end end |
#start ⇒ Object
Initializes and starts a Celluloid::IO-powered TCP-recipient
19 20 21 22 23 |
# File 'lib/listen/adapter/tcp.rb', line 19 def start @socket = TCPSocket.new(listener.host, listener.port) @buffer = String.new run end |