class MogileFS::Socket
Public Class Methods
start(host, port)
click to toggle source
Calls superclass method
# File lib/mogilefs/socket/kgio.rb, line 7 def self.start(host, port) sock = super(Socket.sockaddr_in(port, host)) sock.post_init(host, port) end
tcp(host, port, timeout = 5)
click to toggle source
# File lib/mogilefs/socket/kgio.rb, line 12 def self.tcp(host, port, timeout = 5) sock = start(host, port) unless sock.kgio_wait_writable(timeout) sock.close raise MogileFS::Timeout, 'socket connect timeout' end sock end
Public Instance Methods
timed_peek(len, dst, timeout = 5)
click to toggle source
# File lib/mogilefs/socket/kgio.rb, line 30 def timed_peek(len, dst, timeout = 5) case rc = kgio_trypeek(len, dst) when :wait_readable kgio_wait_readable(timeout) or unreadable_socket!(timeout) else return rc end while true end
timed_read(len, dst = "", timeout = 5)
click to toggle source
# File lib/mogilefs/socket/kgio.rb, line 21 def timed_read(len, dst = "", timeout = 5) case rc = kgio_tryread(len, dst) when :wait_readable kgio_wait_readable(timeout) or unreadable_socket!(timeout) else return rc end while true end
timed_write(buf, timeout = 5)
click to toggle source
# File lib/mogilefs/socket/kgio.rb, line 39 def timed_write(buf, timeout = 5) written = 0 expect = buf.bytesize case rc = kgio_trywrite(buf) when :wait_writable kgio_wait_writable(timeout) or request_truncated!(written, expect, timeout) when String written += expect - rc.bytesize buf = rc else return expect end while true end
wait_writable(timeout = nil)
click to toggle source
# File lib/mogilefs/socket/pure_ruby.rb, line 33 def wait_writable(timeout = nil) IO.select(nil, [ self ], nil, timeout) end