Module: BaseSocket

Included in:
EM::FTPD::ActiveSocket, EM::FTPD::PassiveSocket
Defined in:
lib/em-ftpd/base_socket.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#abortedObject (readonly)

Returns the value of attribute aborted.



3
4
5
# File 'lib/em-ftpd/base_socket.rb', line 3

def aborted
  @aborted
end

Instance Method Details

#abortObject



43
44
45
46
# File 'lib/em-ftpd/base_socket.rb', line 43

def abort
  @aborted = true
  close_connection_after_writing
end

#dataObject



19
20
21
# File 'lib/em-ftpd/base_socket.rb', line 19

def data
  @data ||= ""
end

#initializeObject



5
6
7
8
# File 'lib/em-ftpd/base_socket.rb', line 5

def initialize
  @on_stream = nil
  @aborted = false
end

#on_stream(&blk) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/em-ftpd/base_socket.rb', line 10

def on_stream &blk
  @on_stream = blk if block_given?
  unless data.empty?
    @on_stream.call(data) # send all data that was collected before the stream hanlder was set
    @data = ""
  end
  @on_stream
end

#receive_data(chunk) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/em-ftpd/base_socket.rb', line 23

def receive_data(chunk)
  if @on_stream
    @on_stream.call(chunk)
  else
    data << chunk
  end
end

#unbindObject



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/em-ftpd/base_socket.rb', line 31

def unbind
  if @aborted
    fail
  else
    if @on_stream
      succeed
    else
      succeed data
    end
  end
end