Object
Like TCPSocket.new(host, port), but with an explicit timeout (and we don’t care for local address/port we’re binding to). This raises MogileFS::Timeout if timeout expires
# File lib/mogilefs/util.rb, line 161 def mogilefs_new(host, port, timeout = 5.0) sock = mogilefs_new_nonblock(host, port) or return sock while timeout > 0 t0 = Time.now r = IO.select(nil, [sock], nil, timeout) return sock if r && r[1] && sock.mogilefs_init timeout -= (Time.now - t0) end sock.close rescue nil raise MogileFS::Timeout, 'socket write timeout' end
Creates a new (TCP) Socket and initiates (but does not wait for) the connection
# File lib/mogilefs/util.rb, line 148 def mogilefs_new_nonblock(host, port) sock = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM, 0) sock.sync = true if defined?(Socket::TCP_NODELAY) sock.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1) end sock.mogilefs_init(host, port) sock end
Makes a request on a new TCP Socket and returns with a readble socket within the given timeout. This raises MogileFS::Timeout if timeout expires
# File lib/mogilefs/util.rb, line 180 def mogilefs_new_request(host, port, request, timeout = 5.0) t0 = Time.now sock = mogilefs_new(host, port, timeout) syswrite_full(sock, request, timeout) timeout -= (Time.now - t0) if timeout < 0 sock.close rescue nil raise MogileFS::Timeout, 'socket read timeout' end r = IO.select([sock], nil, nil, timeout) return sock if r && r[0] sock.close rescue nil raise MogileFS::Timeout, 'socket read timeout' end
(Not documented)
# File lib/mogilefs/util.rb, line 129 def mogilefs_init(host = nil, port = nil) return true if defined?(@mogilefs_connected) @mogilefs_addr = Socket.sockaddr_in(port, host).freeze if port && host begin connect_nonblock(@mogilefs_addr) @mogilefs_connected = true rescue Errno::EINPROGRESS nil rescue Errno::EISCONN @mogilefs_connected = true end end
Socket lacks peeraddr method of the IPSocket/TCPSocket classes
# File lib/mogilefs/util.rb, line 125 def mogilefs_peername Socket.unpack_sockaddr_in(getpeername).reverse.map {|x| x.to_s }.join(':') end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.