Files

MogileFS::SocketCommon

Constants

SEP_RE

Attributes

mogilefs_addr[R]

Public Instance Methods

post_init(host, port) click to toggle source
# File lib/mogilefs/socket_common.rb, line 7
def post_init(host, port)
  @mogilefs_addr = "#{host}:#{port}"
  Socket.const_defined?(:TCP_NODELAY) and
    setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
  self
end
read(size, buf = "", timeout = 5) click to toggle source
# File lib/mogilefs/socket_common.rb, line 43
def read(size, buf = "", timeout = 5)
  timed_read(size, buf, timeout) or return # nil/EOF

  while (remaining = size - buf.bytesize) > 0
    tmp ||= ""
    timed_read(remaining, tmp, timeout) or return buf # truncated
    buf << tmp
  end

  buf # full read
end
readpartial(size, buf = "", timeout = 5) click to toggle source
# File lib/mogilefs/socket_common.rb, line 55
def readpartial(size, buf = "", timeout = 5)
  timed_read(size, buf, timeout) or raise EOFError, "end of file reached"
end
request_truncated!(written, expect, timeout) click to toggle source
# File lib/mogilefs/socket_common.rb, line 19
def request_truncated!(written, expect, timeout)
  timeout = timeout.inspect
  raise MogileFS::RequestTruncatedError,
   "request truncated (sent #{written} expected #{expect} timeout=#{timeout})"
end
timed_gets(timeout = 5) click to toggle source
# File lib/mogilefs/socket_common.rb, line 26
def timed_gets(timeout = 5)
  unless defined?(@rbuf) && @rbuf
    @rbuf = timed_read(1024, "", timeout) or return # EOF
  end
  begin
    @rbuf.sub!(SEP_RE, "") and return $1
    tmp ||= ""
    if timed_read(1024, tmp, timeout)
      @rbuf << tmp
    else
      # EOF, return the last buffered bit even without SEP_RE matching
      # (not ideal for MogileFS, this is an error)
      return @rbuf.empty? ? nil : @rbuf.slice!(0, @rbuf.size)
    end
  end while true
end
unreadable_socket!(timeout) click to toggle source
# File lib/mogilefs/socket_common.rb, line 14
def unreadable_socket!(timeout)
  raise MogileFS::UnreadableSocketError,
        "#@mogilefs_addr never became readable (timeout=#{timeout.inspect})"
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.