Class: TCPSocket

Inherits:
IPSocket show all
Defined in:
lib/rubysl/socket/socket.rb

Direct Known Subclasses

TCPServer

Constant Summary collapse

FFI =
Rubinius::FFI

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from IPSocket

#addr, getaddress, #peeraddr, #recvfrom, #recvfrom_nonblock

Methods inherited from BasicSocket

#close_read, #close_write, do_not_reverse_lookup, do_not_reverse_lookup=, for_fd, from_descriptor, #getpeername, #getsockname, #getsockopt, #recv, #recv_nonblock, #recvfrom, #setsockopt, #shutdown

Constructor Details

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

Returns a new instance of TCPSocket.



1068
1069
1070
1071
1072
1073
# File 'lib/rubysl/socket/socket.rb', line 1068

def initialize(host, port, local_host=nil, local_service=nil)
  @host = host
  @port = port

  tcp_setup @host, @port, local_host, local_service
end

Class Method Details

.gethostbyname(hostname) ⇒ Object



1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
# File 'lib/rubysl/socket/socket.rb', line 1044

def self.gethostbyname(hostname)
  addrinfos = Socket.getaddrinfo(hostname, nil)

  hostname     = addrinfos.first[2]
  family       = addrinfos.first[4]
  addresses    = []
  alternatives = []
  addrinfos.each do |a|
    alternatives << a[2] unless a[2] == hostname
    addresses    << a[3] if a[4] == family
  end

  [hostname, alternatives.uniq, family] + addresses.uniq
end

Instance Method Details

#from_descriptor(descriptor) ⇒ Object



1180
1181
1182
1183
1184
# File 'lib/rubysl/socket/socket.rb', line 1180

def from_descriptor(descriptor)
  IO.setup self, descriptor, nil, true

  self
end

#send(bytes_to_read, flags, to = nil) ⇒ Object



1063
1064
1065
# File 'lib/rubysl/socket/socket.rb', line 1063

def send(bytes_to_read, flags, to = nil)
  super(bytes_to_read, flags)
end