Class: BBFS::ContentServer::ContentDataReceiver

Inherits:
Object
  • Object
show all
Defined in:
lib/content_server/content_receiver.rb

Instance Method Summary collapse

Constructor Details

#initialize(queue, port) ⇒ ContentDataReceiver

Returns a new instance of ContentDataReceiver.



9
10
11
12
# File 'lib/content_server/content_receiver.rb', line 9

def initialize queue, port
  @queue = queue
  @port = port
end

Instance Method Details

#runObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/content_server/content_receiver.rb', line 14

def run
  Socket.tcp_server_loop(@port) do |sock, client_addrinfo|
    while size_of_data = sock.read(4)
      size_of_data = size_of_data.unpack("l")[0]
      Log.debug3 "Size of data: #{size_of_data}"
      data = sock.read(size_of_data)
      #Log.debug3 "Data received: #{data}"
      unmarshaled_data = Marshal.load(data)
      #Log.debug3 "Unmarshaled data: #{unmarshaled_data}"
      @queue.push unmarshaled_data
      Log.debug3 "Socket closed? #{sock.closed?}."
      break if sock.closed?
      Log.debug1 'Waiting on sock.read'
    end
    Log.debug1 'Exited, socket closed or read returned nil.'
  end
end