class Socket::HostnameResolutionQueue

Public Class Methods

new(size) click to toggle source
# File socket/lib/socket.rb, line 1049
def initialize(size)
  @size = size
  @taken_count = 0
  @rpipe, @wpipe = IO.pipe
  @queue = Queue.new
  @mutex = Mutex.new
end

Public Instance Methods

add_error(family, error) click to toggle source
# File socket/lib/socket.rb, line 1068
def add_error(family, error)
  @mutex.synchronize do
    @queue.push [family, error]
    @wpipe.putc HOSTNAME_RESOLUTION_QUEUE_UPDATED
  end
end
add_resolved(family, resolved_addrinfos) click to toggle source
# File socket/lib/socket.rb, line 1061
def add_resolved(family, resolved_addrinfos)
  @mutex.synchronize do
    @queue.push [family, resolved_addrinfos]
    @wpipe.putc HOSTNAME_RESOLUTION_QUEUE_UPDATED
  end
end
close_all() click to toggle source
# File socket/lib/socket.rb, line 1098
def close_all
  @queue.close unless @queue.closed?
  @rpipe.close unless @rpipe.closed?
  @wpipe.close unless @wpipe.closed?
end
closed?() click to toggle source
# File socket/lib/socket.rb, line 1090
def closed?
  @rpipe.closed?
end
get() click to toggle source
# File socket/lib/socket.rb, line 1075
def get
  return nil if @queue.empty?

  res = nil

  @mutex.synchronize do
    @rpipe.getbyte
    res = @queue.pop
  end

  @taken_count += 1
  close_all if @taken_count == @size
  res
end
opened?() click to toggle source
# File socket/lib/socket.rb, line 1094
def opened?
  !closed?
end
waiting_pipe() click to toggle source
# File socket/lib/socket.rb, line 1057
def waiting_pipe
  [@rpipe]
end