blob 31b8dec1038acdefb870a47bc514ffb5b216e7ed 1299 bytes (raw)
name: lib/rainbows/revactor/client/tee_socket.rb # note: path name is non-authoritative(*)
# -*- encoding: binary -*-
# 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.
# 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
# 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]
# just proxy any remaining methods TeeInput may use
solving 31b8dec ...
found 31b8dec in https://yhbt.net/rainbows.git/
(*) Git path names are given by the tree(s) the blob belongs to.
Blobs themselves have no identifier aside from the hash of its contents.^
Code repositories for project(s) associated with this public inbox
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).