Class: 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.



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

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

Instance Method Details

#runObject



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

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.debug2("Size of data: %s", size_of_data)
      data = sock.read(size_of_data)
      unmarshaled_data = Marshal.load(data)
      @queue.push unmarshaled_data
      Log.debug2("Socket closed? %s.", sock.closed?)
      break if sock.closed?
      Log.debug2('Waiting on sock.read')
    end
    Log.debug2('Exited, socket closed or read returned nil.')
  end
end