Class: DTAS::UNIXAccepted
- Inherits:
-
Object
- Object
- DTAS::UNIXAccepted
- Defined in:
- lib/dtas/unix_accepted.rb
Overview
an accepted (client) socket in dtas-player server
Instance Attribute Summary collapse
-
#to_io ⇒ Object
readonly
:nodoc:.
Instance Method Summary collapse
- #close ⇒ Object
- #closed? ⇒ Boolean
-
#emit(msg) ⇒ Object
public API (for DTAS::Player) returns :wait_readable on success.
-
#initialize(sock) ⇒ UNIXAccepted
constructor
A new instance of UNIXAccepted.
- #readable_iter ⇒ Object
-
#writable_iter ⇒ Object
flushes pending data if it got buffered.
Constructor Details
#initialize(sock) ⇒ UNIXAccepted
Returns a new instance of UNIXAccepted.
11 12 13 14 |
# File 'lib/dtas/unix_accepted.rb', line 11 def initialize(sock) @to_io = sock @sbuf = [] end |
Instance Attribute Details
#to_io ⇒ Object (readonly)
:nodoc:
9 10 11 |
# File 'lib/dtas/unix_accepted.rb', line 9 def to_io @to_io end |
Instance Method Details
#close ⇒ Object
64 65 66 |
# File 'lib/dtas/unix_accepted.rb', line 64 def close @to_io.close end |
#closed? ⇒ Boolean
68 69 70 |
# File 'lib/dtas/unix_accepted.rb', line 68 def closed? @to_io.closed? end |
#emit(msg) ⇒ Object
public API (for DTAS::Player) returns :wait_readable on success
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/dtas/unix_accepted.rb', line 18 def emit(msg) if @sbuf.empty? case rv = @to_io.sendmsg_nonblock(msg, Socket::MSG_EOR, exception: false) when :wait_writable @sbuf << msg rv else :wait_readable end else @sbuf << msg :wait_writable end rescue => e e end |
#readable_iter ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/dtas/unix_accepted.rb', line 47 def readable_iter nread = @to_io.nread # EOF, assume no spurious wakeups for SOCK_SEQPACKET return nil if nread == 0 case msg = @to_io.recv_nonblock(nread, exception: false) when :wait_readable then return msg when '', nil then return nil # EOF else yield(self, msg) # DTAS::Player deals with this end @sbuf.empty? ? :wait_readable : :wait_writable rescue SystemCallError nil end |
#writable_iter ⇒ Object
flushes pending data if it got buffered
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/dtas/unix_accepted.rb', line 36 def writable_iter case @to_io.sendmsg_nonblock(@sbuf[0], Socket::MSG_EOR, exception: false) when :wait_writable then return :wait_writable else @sbuf.shift @sbuf.empty? ? :wait_readable : :wait_writable end rescue => e e end |