45 |
45 |
# If a block is given the created socket is yielded for each address.
|
46 |
46 |
#
|
47 |
47 |
def connect_internal(local_addrinfo, timeout=nil) # :yields: socket
|
48 |
|
sock = Socket.new(self.pfamily, self.socktype, self.protocol)
|
|
48 |
sock = self.socket
|
49 |
49 |
begin
|
50 |
50 |
sock.ipv6only! if self.ipv6?
|
51 |
51 |
sock.bind local_addrinfo if local_addrinfo
|
... | ... | |
172 |
172 |
# }
|
173 |
173 |
#
|
174 |
174 |
def bind
|
175 |
|
sock = Socket.new(self.pfamily, self.socktype, self.protocol)
|
|
175 |
sock = self.socket
|
176 |
176 |
begin
|
177 |
177 |
sock.ipv6only! if self.ipv6?
|
178 |
178 |
sock.setsockopt(:SOCKET, :REUSEADDR, 1)
|
... | ... | |
189 |
189 |
|
190 |
190 |
# creates a listening socket bound to self.
|
191 |
191 |
def listen(backlog=Socket::SOMAXCONN)
|
192 |
|
sock = Socket.new(self.pfamily, self.socktype, self.protocol)
|
|
192 |
sock = self.socket
|
193 |
193 |
begin
|
194 |
194 |
sock.ipv6only! if self.ipv6?
|
195 |
195 |
sock.setsockopt(:SOCKET, :REUSEADDR, 1)
|
... | ... | |
205 |
205 |
end
|
206 |
206 |
end
|
207 |
207 |
|
|
208 |
# Creates a socket from Addrinfo that is not bound or connected.
|
|
209 |
#
|
|
210 |
# Note that you must have set a protocol family in Addrinfo.new or by using
|
|
211 |
# Addrinfo.udp or Addrinfo.tcp.
|
|
212 |
def socket
|
|
213 |
Socket.new(self.pfamily, self.socktype, self.protocol)
|
|
214 |
end
|
|
215 |
|
208 |
216 |
# iterates over the list of Addrinfo objects obtained by Addrinfo.getaddrinfo.
|
209 |
217 |
#
|
210 |
218 |
# Addrinfo.foreach(nil, 80) {|x| p x }
|
... | ... | |
358 |
366 |
port = nil
|
359 |
367 |
ai_list.each {|ai|
|
360 |
368 |
begin
|
361 |
|
s = Socket.new(ai.pfamily, ai.socktype, ai.protocol)
|
|
369 |
s = ai.socket
|
362 |
370 |
rescue SystemCallError
|
363 |
371 |
next
|
364 |
372 |
end
|