Class: Hop::WssBearer::BufferedSocket

Inherits:
Object
  • Object
show all
Defined in:
lib/hop/wss_bearer.rb

Instance Method Summary collapse

Constructor Details

#initialize(sock, initial) ⇒ BufferedSocket

Returns a new instance of BufferedSocket.



383
384
385
386
# File 'lib/hop/wss_bearer.rb', line 383

def initialize(sock, initial)
  @sock = sock
  @buffer = initial
end

Instance Method Details

#closeObject



399
# File 'lib/hop/wss_bearer.rb', line 399

def close = @sock.close

#read_nonblock(n, exception: true) ⇒ Object



388
389
390
391
392
393
394
395
# File 'lib/hop/wss_bearer.rb', line 388

def read_nonblock(n, exception: true)
  unless @buffer.empty?
    chunk = @buffer.byteslice(0, n)
    @buffer = @buffer.byteslice(chunk.bytesize..) || "".b
    return chunk
  end
  @sock.read_nonblock(n, exception: exception)
end

#to_ioObject



398
# File 'lib/hop/wss_bearer.rb', line 398

def to_io = @sock.to_io

#write_nonblock(data, exception: true) ⇒ Object



397
# File 'lib/hop/wss_bearer.rb', line 397

def write_nonblock(data, exception: true) = @sock.write_nonblock(data, exception: exception)