Class: Flic::Protocol::Connection
- Inherits:
-
Object
- Object
- Flic::Protocol::Connection
- Defined in:
- lib/flic/protocol/connection.rb
Overview
A wrapper around a socket that allows sending/receiving commands/events
Defined Under Namespace
Classes: UnderlyingSocketClosedError, UnexpectedNilReturnValueFromRead
Instance Attribute Summary collapse
-
#socket ⇒ Socket
readonly
The underlying socket.
Instance Method Summary collapse
-
#initialize(socket) ⇒ Connection
constructor
A new instance of Connection.
-
#recv_command ⇒ Flic::Protocol::Commands::Command
Receives a command from the socket.
-
#recv_event ⇒ Flic::Protocol::Events::Event
Receives an event from the socket.
-
#send_command(command) ⇒ Object
Sends a command over the socket.
-
#send_event(event) ⇒ Object
Sends an event over the socket.
Constructor Details
#initialize(socket) ⇒ Connection
Returns a new instance of Connection.
13 14 15 16 17 |
# File 'lib/flic/protocol/connection.rb', line 13 def initialize(socket) @socket = socket @read_semaphore = Mutex.new @write_semaphore = Mutex.new end |
Instance Attribute Details
#socket ⇒ Socket (readonly)
Returns the underlying socket.
11 12 13 |
# File 'lib/flic/protocol/connection.rb', line 11 def socket @socket end |
Instance Method Details
#recv_command ⇒ Flic::Protocol::Commands::Command
Note:
This method may block
Receives a command from the socket
28 29 30 |
# File 'lib/flic/protocol/connection.rb', line 28 def recv_command Protocol.parse_command(recv_packet) end |
#recv_event ⇒ Flic::Protocol::Events::Event
Note:
This method may block
Receives an event from the socket
41 42 43 |
# File 'lib/flic/protocol/connection.rb', line 41 def recv_event Protocol.parse_event(recv_packet) end |
#send_command(command) ⇒ Object
Sends a command over the socket
21 22 23 |
# File 'lib/flic/protocol/connection.rb', line 21 def send_command(command) send_packet Protocol.serialize_command(command) end |
#send_event(event) ⇒ Object
Sends an event over the socket
34 35 36 |
# File 'lib/flic/protocol/connection.rb', line 34 def send_event(event) send_packet Protocol.serialize_event(event) end |