Parent

Included Modules

Socket

Constants

TCP_CORK
(Not documented)

Attributes

mogilefs_addr[RW]

(Not documented)

mogilefs_connected[RW]

(Not documented)

mogilefs_size[RW]

(Not documented)

Public Class Methods

mogilefs_new(host, port, timeout = 5.0) click to toggle source

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
mogilefs_new_nonblock(host, port) click to toggle source

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
mogilefs_new_request(host, port, request, timeout = 5.0) click to toggle source

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

Public Instance Methods

mogilefs_init(host = nil, port = nil) click to toggle source

(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
mogilefs_peername() click to toggle source

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
mogilefs_tcp_cork=(set) click to toggle source

(Not documented)

# File lib/mogilefs/util.rb, line 117
  def mogilefs_tcp_cork=(set)
    if defined?(TCP_CORK)
      self.setsockopt(SOL_TCP, TCP_CORK, set ? 1 : 0) rescue nil
    end
    set
  end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.