Class: Riser::TCPSocketAddress

Inherits:
SocketAddress show all
Defined in:
lib/riser/sockaddr.rb

Instance Attribute Summary collapse

Attributes inherited from SocketAddress

#backlog, #type

Instance Method Summary collapse

Methods inherited from SocketAddress

#==, #eql?, #hash, parse, #to_option

Constructor Details

#initialize(host, port, backlog = nil) ⇒ TCPSocketAddress

Returns a new instance of TCPSocketAddress.



100
101
102
103
104
# File 'lib/riser/sockaddr.rb', line 100

def initialize(host, port, backlog=nil)
  super(:tcp, backlog)
  @host = host
  @port = port
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



106
107
108
# File 'lib/riser/sockaddr.rb', line 106

def host
  @host
end

#portObject (readonly)

Returns the value of attribute port.



107
108
109
# File 'lib/riser/sockaddr.rb', line 107

def port
  @port
end

Instance Method Details

#open_serverObject



121
122
123
# File 'lib/riser/sockaddr.rb', line 121

def open_server
  TCPServer.new(@host, @port)
end

#to_addressObject



109
110
111
# File 'lib/riser/sockaddr.rb', line 109

def to_address
  super << @host <<  @port
end

#to_sObject



113
114
115
116
117
118
119
# File 'lib/riser/sockaddr.rb', line 113

def to_s
  if (@host.include? ':') then
    "tcp://[#{host}]:#{port}"
  else
    "tcp://#{host}:#{port}"
  end
end