mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
update doc.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27009 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
1a40be09d6
commit
1561d3fb8b
4 changed files with 30 additions and 1 deletions
|
@ -348,6 +348,8 @@ bsock_getsockopt(VALUE sock, VALUE lev, VALUE optname)
|
|||
* TCPServer.open("127.0.0.1", 15120) {|serv|
|
||||
* p serv.getsockname #=> "\x02\x00;\x10\x7F\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00"
|
||||
* }
|
||||
*
|
||||
* If Addrinfo object is preferred, use BasicSocket#local_address.
|
||||
*/
|
||||
static VALUE
|
||||
bsock_getsockname(VALUE sock)
|
||||
|
@ -374,6 +376,8 @@ bsock_getsockname(VALUE sock)
|
|||
* p s.getpeername #=> "\x02\x00\x82u\x7F\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00"
|
||||
* }
|
||||
*
|
||||
* If Addrinfo object is preferred, use BasicSocket#remote_address.
|
||||
*
|
||||
*/
|
||||
static VALUE
|
||||
bsock_getpeername(VALUE sock)
|
||||
|
|
|
@ -264,7 +264,7 @@ ip_recvfrom(int argc, VALUE *argv, VALUE sock)
|
|||
* call-seq:
|
||||
* IPSocket.getaddress(host) => ipaddress
|
||||
*
|
||||
* Lookups IP address of _host_.
|
||||
* Lookups the IP address of _host_.
|
||||
*
|
||||
* IPSocket.getaddress("localhost") #=> "127.0.0.1"
|
||||
* IPSocket.getaddress("ip6-localhost") #=> "::1"
|
||||
|
|
|
@ -1097,6 +1097,8 @@ sock_s_getservbyport(int argc, VALUE *argv)
|
|||
* +true+, +:hostname+: hostname is obtained from numeric address using reverse lookup, which may take a time.
|
||||
* +false+, +:numeric+: hostname is same as numeric address.
|
||||
* +nil+: obey to the current +do_not_reverse_lookup+ flag.
|
||||
*
|
||||
* If Addrinfo object is preferred, use Addrinfo.getaddrinfo.
|
||||
*/
|
||||
static VALUE
|
||||
sock_s_getaddrinfo(int argc, VALUE *argv)
|
||||
|
@ -1147,6 +1149,8 @@ sock_s_getaddrinfo(int argc, VALUE *argv)
|
|||
* Socket.getnameinfo(Socket.sockaddr_in(80, "127.0.0.1")) #=> ["localhost", "www"]
|
||||
* Socket.getnameinfo(["AF_INET", 80, "127.0.0.1"]) #=> ["localhost", "www"]
|
||||
* Socket.getnameinfo(["AF_INET", 80, "localhost", "127.0.0.1"]) #=> ["localhost", "www"]
|
||||
*
|
||||
* If Addrinfo object is preferred, use Addrinfo#getnameinfo.
|
||||
*/
|
||||
static VALUE
|
||||
sock_s_getnameinfo(int argc, VALUE *argv)
|
||||
|
@ -1798,6 +1802,15 @@ socket_s_ip_address_list(VALUE self)
|
|||
* information on particular exception is needed please refer to the
|
||||
* Unix manual pages or the Windows WinSock reference.
|
||||
*
|
||||
* === Convenient methods
|
||||
*
|
||||
* Although the general way to create socket is Socket.new,
|
||||
* there are several methods for socket creation for most cases.
|
||||
*
|
||||
* * TCP client socket: Socket.tcp, TCPSocket.open
|
||||
* * TCP server socket: Socket.tcp_server_loop, TCPServer.open
|
||||
* * UNIX client socket: Socket.unix, UNIXSocket.open
|
||||
* * UNIX server socket: Socket.unix_server_loop, UNIXServer.open
|
||||
*
|
||||
* === Documentation by
|
||||
* * Zach Dennis
|
||||
|
|
|
@ -2,7 +2,9 @@ require 'socket'
|
|||
require 'resolv'
|
||||
|
||||
class << IPSocket
|
||||
# :stopdoc:
|
||||
alias original_resolv_getaddress getaddress
|
||||
# :startdoc:
|
||||
def getaddress(host)
|
||||
begin
|
||||
return Resolv.getaddress(host).to_s
|
||||
|
@ -13,7 +15,9 @@ class << IPSocket
|
|||
end
|
||||
|
||||
class TCPSocket < IPSocket
|
||||
# :stopdoc:
|
||||
alias original_resolv_initialize initialize
|
||||
# :startdoc:
|
||||
def initialize(host, serv, *rest)
|
||||
rest[0] = IPSocket.getaddress(rest[0]) unless rest.empty?
|
||||
original_resolv_initialize(IPSocket.getaddress(host), serv, *rest)
|
||||
|
@ -21,18 +25,24 @@ class TCPSocket < IPSocket
|
|||
end
|
||||
|
||||
class UDPSocket < IPSocket
|
||||
# :stopdoc:
|
||||
alias original_resolv_bind bind
|
||||
# :startdoc:
|
||||
def bind(host, port)
|
||||
host = IPSocket.getaddress(host) if host != ""
|
||||
original_resolv_bind(host, port)
|
||||
end
|
||||
|
||||
# :stopdoc:
|
||||
alias original_resolv_connect connect
|
||||
# :startdoc:
|
||||
def connect(host, port)
|
||||
original_resolv_connect(IPSocket.getaddress(host), port)
|
||||
end
|
||||
|
||||
# :stopdoc:
|
||||
alias original_resolv_send send
|
||||
# :startdoc:
|
||||
def send(mesg, flags, *rest)
|
||||
if rest.length == 2
|
||||
host, port = rest
|
||||
|
@ -56,7 +66,9 @@ class UDPSocket < IPSocket
|
|||
end
|
||||
|
||||
class SOCKSSocket < TCPSocket
|
||||
# :stopdoc:
|
||||
alias original_resolv_initialize initialize
|
||||
# :startdoc:
|
||||
def initialize(host, serv)
|
||||
original_resolv_initialize(IPSocket.getaddress(host), port)
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue