Class: Cosmos::Stream

Inherits:
Object show all
Defined in:
lib/cosmos/streams/stream.rb

Overview

Class that implments the following methods: read, write(data), connect, connected? and disconnect. Streams are simply data sources which Protocol classes read and write to. This separation of concerns allows Streams to simply focus on getting and sending raw data while the higher level processing occurs in Protocol.

Direct Known Subclasses

SerialStream, TcpipSocketStream

Instance Method Summary collapse

Instance Method Details

#connectObject

Connects the stream



48
49
50
# File 'lib/cosmos/streams/stream.rb', line 48

def connect
  raise "connect not defined by Stream"
end

#connected?Boolean

Returns true if connected or false otherwise.

Returns:

  • (Boolean)

    true if connected or false otherwise



53
54
55
# File 'lib/cosmos/streams/stream.rb', line 53

def connected?
  raise "connected? not defined by Stream"
end

#disconnectObject

Disconnects the stream Note that streams are not designed to be reconnected and must be recreated



59
60
61
# File 'lib/cosmos/streams/stream.rb', line 59

def disconnect
  raise "disconnect not defined by Stream"
end

#readObject

Expected to return any amount of data on success, or a blank string on closed/EOF, and may raise Timeout::Error, or other errors



29
30
31
# File 'lib/cosmos/streams/stream.rb', line 29

def read
  raise "read not defined by Stream"
end

#read_nonblockObject

Expected to always return immediately with data if available or an empty string. Should not raise errors



35
36
37
# File 'lib/cosmos/streams/stream.rb', line 35

def read_nonblock
  raise "read_nonblock not defined by Stream"
end

#write(data) ⇒ Object

Expected to write complete set of data. May raise Timeout::Error or other errors.

Parameters:

  • data (String)

    Binary data to write to the stream



43
44
45
# File 'lib/cosmos/streams/stream.rb', line 43

def write(data)
  raise "write not defined by Stream"
end