Class: TCPSocket

Inherits:
IPSocket show all
Defined in:
mrbgems/mruby-socket/src/socket.c,
mrbgems/mruby-socket/mrblib/socket.rb

Direct Known Subclasses

TCPServer

Constant Summary

Constants inherited from IO

IO::BUF_SIZE, IO::SEEK_CUR, IO::SEEK_END, IO::SEEK_SET

Instance Attribute Summary

Attributes inherited from BasicSocket

#do_not_reverse_lookup

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from IPSocket

#addr, getaddress, #peeraddr, #recvfrom

Methods inherited from BasicSocket

#_is_socket=, #_recvfrom, #_setnonblock, #close, do_not_reverse_lookup, do_not_reverse_lookup=, for_fd, #getpeereid, #getpeername, #getsockname, #getsockopt, #local_address, #recv, #recv_nonblock, #remote_address, #send, #setsockopt, #shutdown, #sysread, #sysseek, #syswrite

Methods inherited from IO

#<<, #_check_readable, #_read_buf, #close, #close_on_exec=, #close_on_exec?, #close_write, #closed?, #each, #each_byte, #eof?, #fileno, #flush, #getc, #gets, #hash, #initialize_copy, #isatty, open, #pid, pipe, popen, #pos, #pos=, #print, #printf, #puts, read, #read, #readchar, #readline, #readlines, #rewind, #seek, #sync, #sync=, #sysread, #sysseek, #syswrite, #ungetc, #write

Constructor Details

#initialize(host, service, local_host = nil, local_service = nil) ⇒ TCPSocket

Returns a new instance of TCPSocket



231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
# File 'mrbgems/mruby-socket/mrblib/socket.rb', line 231

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(pre, *args) ⇒ Object



257
258
259
260
261
262
# File 'mrbgems/mruby-socket/mrblib/socket.rb', line 257

def self.new_with_prelude pre, *args
  o = self._allocate
  o.instance_eval(&pre)
  o.initialize(*args)
  o
end