Class: LightIO::Library::TCPSocket
- Inherits:
-
IPSocket
- Object
- IO
- BasicSocket
- IPSocket
- LightIO::Library::TCPSocket
- Includes:
- Base
- Defined in:
- lib/lightio/library/socket.rb
Direct Known Subclasses
Instance Method Summary collapse
-
#initialize(*args) ⇒ TCPSocket
constructor
A new instance of TCPSocket.
Methods included from Base
Methods inherited from BasicSocket
Methods included from Module::BasicSocket::ClassMethods
Methods included from Wrap::IOWrapper
Methods inherited from IO
#binmode, #lineno, #lineno=, #rewind, #seek, #set_encoding, #to_io
Methods included from Module::IO::ClassMethods
#copy_stream, #open, #pipe, #select
Methods included from IO::IOMethods
#close, #eof, #flush, #getbyte, #getc, #gets, #lightio_initialize, #print, #printf, #puts, #read, #readbyte, #readchar, #readline, #readlines, #readpartial, #wait, #wait_readable, #wait_writable, #write
Constructor Details
#initialize(*args) ⇒ TCPSocket
Returns a new instance of TCPSocket.
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/lightio/library/socket.rb', line 142 def initialize(*args) raise ArgumentError, "wrong number of arguments (given #{args.size}, expected 2..4)" if args.size < 2 || args.size > 4 host, port = args[0..1] local_host, local_port = args[2..3] addrinfo = Addrinfo.getaddrinfo(host, port, nil, :STREAM)[0] socket = ::Socket.send(:origin_new, addrinfo.afamily, Socket::SOCK_STREAM, 0) if local_host || local_port local_address = Socket.sockaddr_in(local_port, local_host) socket.bind(local_address) end remote_address = Socket.sockaddr_in(addrinfo.ip_port, addrinfo.ip_address) @obj = socket wait_nonblock(:connect_nonblock, remote_address) @obj lightio_initialize end |