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.



133
134
135
136
137
# File 'lib/riser/sockaddr.rb', line 133

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.



139
140
141
# File 'lib/riser/sockaddr.rb', line 139

def host
  @host
end

#portObject (readonly)

Returns the value of attribute port.



140
141
142
# File 'lib/riser/sockaddr.rb', line 140

def port
  @port
end

Instance Method Details

#open_serverObject



154
155
156
# File 'lib/riser/sockaddr.rb', line 154

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

#to_addressObject



142
143
144
# File 'lib/riser/sockaddr.rb', line 142

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

#to_sObject



146
147
148
149
150
151
152
# File 'lib/riser/sockaddr.rb', line 146

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