Class: Raval::ActiveSocket
- Inherits:
-
Object
- Object
- Raval::ActiveSocket
- Includes:
- Celluloid::IO
- Defined in:
- lib/raval/active_socket.rb
Overview
In Active FTP mode, the client opens a listening data socket on their host and we connect to it.
A different class is used when operating in passive FTP mode. They both have a #read and #write method, so the quack like each other in the ways that matter.
Instance Method Summary collapse
- #close ⇒ Object
- #connect ⇒ Object
- #connected? ⇒ Boolean
-
#initialize(host, port) ⇒ ActiveSocket
constructor
A new instance of ActiveSocket.
- #read ⇒ Object
- #write(data) ⇒ Object
Constructor Details
#initialize(host, port) ⇒ ActiveSocket
Returns a new instance of ActiveSocket.
16 17 18 19 |
# File 'lib/raval/active_socket.rb', line 16 def initialize(host, port) @host, @port = host, port @socket = nil end |
Instance Method Details
#close ⇒ Object
44 45 46 47 |
# File 'lib/raval/active_socket.rb', line 44 def close @socket.close if @socket @socket = nil end |
#connect ⇒ Object
21 22 23 24 25 |
# File 'lib/raval/active_socket.rb', line 21 def connect unless @socket @socket = ::TCPSocket.new(@host, @port) end end |
#connected? ⇒ Boolean
40 41 42 |
# File 'lib/raval/active_socket.rb', line 40 def connected? @socket != nil end |
#read ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/raval/active_socket.rb', line 27 def read connect unless @socket @socket.readpartial(4096) rescue EOFError, Errno::ECONNRESET close nil end |
#write(data) ⇒ Object
35 36 37 38 |
# File 'lib/raval/active_socket.rb', line 35 def write(data) connect unless @socket @socket.write(data) end |