Method: UUID::Server#bind

Defined in:
lib/uuid.rb

#bind(address) ⇒ Object

Returns UNIXServer or TCPServer from address. Returns argument if not a string, so can pass through (see #listen).



371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
# File 'lib/uuid.rb', line 371

def bind(address)
  return address unless String === address
  if address[0] == ?/
    if File.exist?(address)
      raise ArgumentError, "#{address} is not a socket" unless File.socket?(address)
      File.unlink(address)
    end
    sock = UNIXServer.new(address)
    File.chmod 0666, address
  elsif address =~ /^(\d+\.\d+\.\d+\.\d+):(\d+)$/
    sock = TCPServer.new($1, $2.to_i)
  else
    raise ArgumentError, "Don't know how to bind #{address}"
  end
  sock.setsockopt(IPPROTO_TCP, TCP_NODELAY, 1) if defined?(TCP_NODELAY)
  sock
end