Class: Cyc::Connection::ConnectionClient
- Inherits:
-
EventMachine::Connection
- Object
- EventMachine::Connection
- Cyc::Connection::ConnectionClient
- Includes:
- EventMachine::Deferrable
- Defined in:
- lib/cyc/connection/synchrony.rb
Instance Method Summary collapse
- #connected? ⇒ Boolean
- #connection_completed ⇒ Object
- #post_init ⇒ Object
- #read ⇒ Object
- #receive_data(data) ⇒ Object
- #send(data) ⇒ Object
- #unbind ⇒ Object
Instance Method Details
#connected? ⇒ Boolean
21 22 23 |
# File 'lib/cyc/connection/synchrony.rb', line 21 def connected? @connected end |
#connection_completed ⇒ Object
16 17 18 19 |
# File 'lib/cyc/connection/synchrony.rb', line 16 def connection_completed @connected = true succeed end |
#post_init ⇒ Object
10 11 12 13 14 |
# File 'lib/cyc/connection/synchrony.rb', line 10 def post_init @req = [] @connected = false @buffer = DataBuffer.new end |
#read ⇒ Object
42 43 44 |
# File 'lib/cyc/connection/synchrony.rb', line 42 def read EventMachine::Synchrony.sync @req.last unless @req.empty? end |
#receive_data(data) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/cyc/connection/synchrony.rb', line 25 def receive_data(data) @buffer << data begin while (result = @buffer.next_result(@req.first)) unless @req.empty? msg, req = @req.shift(2) req.succeed(result << msg) end end rescue RuntimeError => err @req.each_slice(2) {|_, r| r.fail [:error, err]} @req.clear close_connection end end |
#send(data) ⇒ Object
46 47 48 49 50 |
# File 'lib/cyc/connection/synchrony.rb', line 46 def send(data) @req << data << EventMachine::DefaultDeferrable.new callback { send_data data + EOL } @req.last end |
#unbind ⇒ Object
52 53 54 55 56 57 58 59 60 |
# File 'lib/cyc/connection/synchrony.rb', line 52 def unbind @connected = false @buffer.discard! unless @req.empty? @req.each_slice(2) {|_, r| r.fail [:error, Errno::ECONNRESET]} @req.clear end fail end |