# 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
# 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
# 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
# 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
# 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
Generated with the Darkfish Rdoc Generator 2.