Sha256: c8932e1e4179da09881d9f5ec62752c5e34b8c19a961d5fde787627ccea678f1

Contents?: true

Size: 1.27 KB

Versions: 25

Compression:

Stored size: 1.27 KB

Contents

# -*- encoding: binary -*-
# :enddoc:
#
# Revactor Sockets do not implement readpartial, so we emulate just
# enough to avoid mucking with TeeInput internals.  Fortunately
# this code is not heavily used so we can usually avoid the overhead
# of adding a userspace buffer.
class Rainbows::Revactor::Client::TeeSocket
  def initialize(socket)
    # IO::Buffer is used internally by Rev which Revactor is based on
    # so we'll always have it available
    @socket, @rbuf = socket, IO::Buffer.new
  end

  def leftover
    @rbuf.read
  end

  # Revactor socket reads always return an unspecified amount,
  # sometimes too much
  def kgio_read(length, dst = "")
    return dst.replace("") if length == 0

    # always check and return from the userspace buffer first
    @rbuf.size > 0 and return dst.replace(@rbuf.read(length))

    # read off the socket since there was nothing in rbuf
    tmp = @socket.read

    # we didn't read too much, good, just return it straight back
    # to avoid needlessly wasting memory bandwidth
    tmp.size <= length and return dst.replace(tmp)

    # ugh, read returned too much
    @rbuf << tmp[length, tmp.size]
    dst.replace(tmp[0, length])
    rescue EOFError
  end

  # just proxy any remaining methods TeeInput may use
  def close
    @socket.close
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
rainbows-5.1.1 lib/rainbows/revactor/client/tee_socket.rb
rainbows-5.1.0 lib/rainbows/revactor/client/tee_socket.rb
rainbows-5.0.0.5.ge717 lib/rainbows/revactor/client/tee_socket.rb
rainbows-5.0.0 lib/rainbows/revactor/client/tee_socket.rb
rainbows-4.7.0 lib/rainbows/revactor/client/tee_socket.rb
rainbows-4.6.2 lib/rainbows/revactor/client/tee_socket.rb
rainbows-4.6.1 lib/rainbows/revactor/client/tee_socket.rb
rainbows-4.6.0.4.g4108 lib/rainbows/revactor/client/tee_socket.rb
rainbows-4.6.0 lib/rainbows/revactor/client/tee_socket.rb
rainbows-4.5.0 lib/rainbows/revactor/client/tee_socket.rb
rainbows-4.4.3 lib/rainbows/revactor/client/tee_socket.rb
rainbows-4.4.2 lib/rainbows/revactor/client/tee_socket.rb
rainbows-4.4.1.1.gd5c8c lib/rainbows/revactor/client/tee_socket.rb
rainbows-4.4.1 lib/rainbows/revactor/client/tee_socket.rb
rainbows-4.4.0 lib/rainbows/revactor/client/tee_socket.rb
rainbows-4.3.1 lib/rainbows/revactor/client/tee_socket.rb
rainbows-4.3.0 lib/rainbows/revactor/client/tee_socket.rb
rainbows-4.2.0 lib/rainbows/revactor/client/tee_socket.rb
rainbows-4.1.0 lib/rainbows/revactor/client/tee_socket.rb
rainbows-4.0.0 lib/rainbows/revactor/client/tee_socket.rb