Class: TCPSocket
- Inherits:
-
IPSocket
- Object
- IO
- BasicSocket
- IPSocket
- TCPSocket
- Defined in:
- mrbgems/mruby-socket/mrblib/socket.rb
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from BasicSocket
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(host, service, local_host = nil, local_service = nil) ⇒ TCPSocket
constructor
A new instance of TCPSocket.
Methods inherited from IPSocket
#addr, getaddress, #peeraddr, #recvfrom
Methods inherited from BasicSocket
do_not_reverse_lookup, do_not_reverse_lookup=, for_fd, #local_address, #recv_nonblock, #remote_address
Methods inherited from IO
#<<, #each, #each_byte, #each_char, #hash, open, pipe, popen, #pos=, #print, #printf, #puts, read, #rewind, #ungetbyte
Constructor Details
#initialize(host, service, local_host = nil, local_service = nil) ⇒ TCPSocket
Returns a new instance of TCPSocket.
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
# File 'mrbgems/mruby-socket/mrblib/socket.rb', line 228 def initialize(host, service, local_host=nil, local_service=nil) if @init_with_fd super(host, service) else s = nil e = SocketError Addrinfo.foreach(host, service) { |ai| begin s = Socket._socket(ai.afamily, Socket::SOCK_STREAM, 0) if local_host or local_service local_host ||= (ai.afamily == Socket::AF_INET) ? "0.0.0.0" : "::" local_service ||= "0" bi = Addrinfo.getaddrinfo(local_host, local_service, ai.afamily, ai.socktype)[0] Socket._bind(s, bi.to_sockaddr) end Socket._connect(s, ai.to_sockaddr) super(s, "r+") return rescue => e0 e = e0 end } raise e end end |
Class Method Details
._new_with_prelude(*args, &pre) ⇒ Object
254 255 256 257 258 259 |
# File 'mrbgems/mruby-socket/mrblib/socket.rb', line 254 def self._new_with_prelude(*args, &pre) o = self._allocate o.instance_eval(&pre) o.initialize(*args) o end |