Class: GrpcKit::Session::SendBuffer
- Inherits:
-
Object
- Object
- GrpcKit::Session::SendBuffer
- Defined in:
- lib/grpc_kit/session/send_buffer.rb
Instance Method Summary collapse
- #empty? ⇒ Boolean
- #end_write ⇒ void
- #end_write? ⇒ Boolean
- #eof? ⇒ Boolean
-
#initialize ⇒ SendBuffer
constructor
A new instance of SendBuffer.
- #need_resume? ⇒ Boolean
- #no_resume ⇒ Object
- #read(size = nil) ⇒ nil, ...
- #write(data, last: false) ⇒ void
Constructor Details
#initialize ⇒ SendBuffer
Returns a new instance of SendBuffer.
6 7 8 9 10 11 |
# File 'lib/grpc_kit/session/send_buffer.rb', line 6 def initialize @buffer = ''.b @end_write = false @deferred_read = false @mutex = Mutex.new end |
Instance Method Details
#empty? ⇒ Boolean
40 41 42 |
# File 'lib/grpc_kit/session/send_buffer.rb', line 40 def empty? @mutex.synchronize { @buffer.empty? } end |
#end_write ⇒ void
This method returns an undefined value.
31 32 33 |
# File 'lib/grpc_kit/session/send_buffer.rb', line 31 def end_write @end_write = true end |
#end_write? ⇒ Boolean
36 37 38 |
# File 'lib/grpc_kit/session/send_buffer.rb', line 36 def end_write? @end_write end |
#eof? ⇒ Boolean
68 69 70 |
# File 'lib/grpc_kit/session/send_buffer.rb', line 68 def eof? end_write? && @mutex.synchronize { @buffer.empty? } end |
#need_resume? ⇒ Boolean
22 23 24 |
# File 'lib/grpc_kit/session/send_buffer.rb', line 22 def need_resume? @deferred_read end |
#no_resume ⇒ Object
26 27 28 |
# File 'lib/grpc_kit/session/send_buffer.rb', line 26 def no_resume @deferred_read = false end |
#read(size = nil) ⇒ nil, ...
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/grpc_kit/session/send_buffer.rb', line 46 def read(size = nil) buf = do_read(size) if buf @deferred_read = false return buf end if end_write? # Call again because #write invokes `@buffer << data` before calling #end_write if (buf = do_read(size)) @deferred_read = false return buf end @deferred_read = false return nil # EOF end @deferred_read = true DS9::ERR_DEFERRED end |
#write(data, last: false) ⇒ void
This method returns an undefined value.
16 17 18 19 |
# File 'lib/grpc_kit/session/send_buffer.rb', line 16 def write(data, last: false) @mutex.synchronize { @buffer << data } end_write if last end |