Method: Networking.read_from_stream
- Defined in:
- lib/networking/tcp.rb
.read_from_stream(stream) ⇒ Object
Returns pair [status(true/false), obj]
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/networking/tcp.rb', line 34 def Networking.read_from_stream(stream) Log.debug3('Read from stream.') begin return [false, nil] unless size_of_data = stream.read(4) size_of_data = size_of_data.unpack("l")[0] Log.debug2("Reading data size:#{size_of_data}") data = stream.read(size_of_data) rescue Exception => e Log.warning("Could not read tcp/ip stream, #{e.to_s}.") begin stream.close() rescue IOError => e Log.warning("Could not close stream, #{e.to_s}.") end return [false, nil] end unmarshalled_data = Marshal.load(data) Log.debug2('Read good.') return [true, unmarshalled_data] end |