Sha256: bf9f599225f119297a39149b46ff899e342bdbe057b89eb283379a3d2e98618b
Contents?: true
Size: 1.03 KB
Versions: 10
Compression:
Stored size: 1.03 KB
Contents
# frozen_string_literal: true module GrpcKit module Session class RecvBuffer def initialize @buffer = +''.b @end = false @mutex = Mutex.new end # @param data [String] # @return [void] def write(data) @mutex.synchronize { @buffer << data } end # @param size [Integer,nil] # @param last [Boolean] # @return [String,nil] def read(size = nil, last: false) buf = @mutex.synchronize do return nil if @buffer.empty? if size.nil? || @buffer.bytesize < size buf = @buffer @buffer = ''.b buf else @buffer.freeze rbuf = @buffer.byteslice(0, size) @buffer = @buffer.byteslice(size, @buffer.bytesize) rbuf end end end_read if last buf end # @return [Boolean] def end_read? @end end # @return [void] def end_read @end = true end end end end
Version data entries
10 entries across 10 versions & 1 rubygems