Class: GrpcKit::Session::IO
- Inherits:
-
Object
- Object
- GrpcKit::Session::IO
- Defined in:
- lib/grpc_kit/session/io.rb
Instance Method Summary collapse
- #close ⇒ Object
- #flush ⇒ void
-
#initialize(io) ⇒ IO
constructor
A new instance of IO.
- #recv_event(length) ⇒ DS9::ERR_WOULDBLOCK, ...
-
#select(timeout = 1) ⇒ void
Blocking until io object is readable or writable.
- #send_event(data) ⇒ DS9::ERR_WOULDBLOCK, Integer
-
#wait_readable ⇒ void
Blocking until io object is readable.
Constructor Details
#initialize(io) ⇒ IO
Returns a new instance of IO.
8 9 10 |
# File 'lib/grpc_kit/session/io.rb', line 8 def initialize(io) @io = io end |
Instance Method Details
#close ⇒ Object
12 13 14 |
# File 'lib/grpc_kit/session/io.rb', line 12 def close @io.close end |
#flush ⇒ void
This method returns an undefined value.
60 61 62 |
# File 'lib/grpc_kit/session/io.rb', line 60 def flush @io.flush end |
#recv_event(length) ⇒ DS9::ERR_WOULDBLOCK, ...
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/grpc_kit/session/io.rb', line 18 def recv_event(length) data = @io.read_nonblock(length, nil, exception: false) case data when :wait_readable DS9::ERR_WOULDBLOCK when nil # nil means EOF DS9::ERR_EOF else data end end |
#select(timeout = 1) ⇒ void
This method returns an undefined value.
Blocking until io object is readable or writable
55 56 57 |
# File 'lib/grpc_kit/session/io.rb', line 55 def select(timeout = 1) ::IO.select([@io], [@io], [], timeout) end |
#send_event(data) ⇒ DS9::ERR_WOULDBLOCK, Integer
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/grpc_kit/session/io.rb', line 33 def send_event(data) return 0 if data.empty? bytes = @io.write_nonblock(data, exception: false) if bytes == :wait_writable DS9::ERR_WOULDBLOCK else bytes end end |
#wait_readable ⇒ void
This method returns an undefined value.
Blocking until io object is readable
46 47 48 49 50 51 |
# File 'lib/grpc_kit/session/io.rb', line 46 def wait_readable ::IO.select([@io], [], []) true rescue IOError false end |