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|
|
* 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"
|
* 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
|
static VALUE
|
||||||
bsock_getsockname(VALUE sock)
|
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"
|
* 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
|
static VALUE
|
||||||
bsock_getpeername(VALUE sock)
|
bsock_getpeername(VALUE sock)
|
||||||
|
|
|
@ -264,7 +264,7 @@ ip_recvfrom(int argc, VALUE *argv, VALUE sock)
|
||||||
* call-seq:
|
* call-seq:
|
||||||
* IPSocket.getaddress(host) => ipaddress
|
* IPSocket.getaddress(host) => ipaddress
|
||||||
*
|
*
|
||||||
* Lookups IP address of _host_.
|
* Lookups the IP address of _host_.
|
||||||
*
|
*
|
||||||
* IPSocket.getaddress("localhost") #=> "127.0.0.1"
|
* IPSocket.getaddress("localhost") #=> "127.0.0.1"
|
||||||
* IPSocket.getaddress("ip6-localhost") #=> "::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.
|
* +true+, +:hostname+: hostname is obtained from numeric address using reverse lookup, which may take a time.
|
||||||
* +false+, +:numeric+: hostname is same as numeric address.
|
* +false+, +:numeric+: hostname is same as numeric address.
|
||||||
* +nil+: obey to the current +do_not_reverse_lookup+ flag.
|
* +nil+: obey to the current +do_not_reverse_lookup+ flag.
|
||||||
|
*
|
||||||
|
* If Addrinfo object is preferred, use Addrinfo.getaddrinfo.
|
||||||
*/
|
*/
|
||||||
static VALUE
|
static VALUE
|
||||||
sock_s_getaddrinfo(int argc, VALUE *argv)
|
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(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, "127.0.0.1"]) #=> ["localhost", "www"]
|
||||||
* Socket.getnameinfo(["AF_INET", 80, "localhost", "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
|
static VALUE
|
||||||
sock_s_getnameinfo(int argc, VALUE *argv)
|
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
|
* information on particular exception is needed please refer to the
|
||||||
* Unix manual pages or the Windows WinSock reference.
|
* 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
|
* === Documentation by
|
||||||
* * Zach Dennis
|
* * Zach Dennis
|
||||||
|
|
|
@ -2,7 +2,9 @@ require 'socket'
|
||||||
require 'resolv'
|
require 'resolv'
|
||||||
|
|
||||||
class << IPSocket
|
class << IPSocket
|
||||||
|
# :stopdoc:
|
||||||
alias original_resolv_getaddress getaddress
|
alias original_resolv_getaddress getaddress
|
||||||
|
# :startdoc:
|
||||||
def getaddress(host)
|
def getaddress(host)
|
||||||
begin
|
begin
|
||||||
return Resolv.getaddress(host).to_s
|
return Resolv.getaddress(host).to_s
|
||||||
|
@ -13,7 +15,9 @@ class << IPSocket
|
||||||
end
|
end
|
||||||
|
|
||||||
class TCPSocket < IPSocket
|
class TCPSocket < IPSocket
|
||||||
|
# :stopdoc:
|
||||||
alias original_resolv_initialize initialize
|
alias original_resolv_initialize initialize
|
||||||
|
# :startdoc:
|
||||||
def initialize(host, serv, *rest)
|
def initialize(host, serv, *rest)
|
||||||
rest[0] = IPSocket.getaddress(rest[0]) unless rest.empty?
|
rest[0] = IPSocket.getaddress(rest[0]) unless rest.empty?
|
||||||
original_resolv_initialize(IPSocket.getaddress(host), serv, *rest)
|
original_resolv_initialize(IPSocket.getaddress(host), serv, *rest)
|
||||||
|
@ -21,18 +25,24 @@ class TCPSocket < IPSocket
|
||||||
end
|
end
|
||||||
|
|
||||||
class UDPSocket < IPSocket
|
class UDPSocket < IPSocket
|
||||||
|
# :stopdoc:
|
||||||
alias original_resolv_bind bind
|
alias original_resolv_bind bind
|
||||||
|
# :startdoc:
|
||||||
def bind(host, port)
|
def bind(host, port)
|
||||||
host = IPSocket.getaddress(host) if host != ""
|
host = IPSocket.getaddress(host) if host != ""
|
||||||
original_resolv_bind(host, port)
|
original_resolv_bind(host, port)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# :stopdoc:
|
||||||
alias original_resolv_connect connect
|
alias original_resolv_connect connect
|
||||||
|
# :startdoc:
|
||||||
def connect(host, port)
|
def connect(host, port)
|
||||||
original_resolv_connect(IPSocket.getaddress(host), port)
|
original_resolv_connect(IPSocket.getaddress(host), port)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# :stopdoc:
|
||||||
alias original_resolv_send send
|
alias original_resolv_send send
|
||||||
|
# :startdoc:
|
||||||
def send(mesg, flags, *rest)
|
def send(mesg, flags, *rest)
|
||||||
if rest.length == 2
|
if rest.length == 2
|
||||||
host, port = rest
|
host, port = rest
|
||||||
|
@ -56,7 +66,9 @@ class UDPSocket < IPSocket
|
||||||
end
|
end
|
||||||
|
|
||||||
class SOCKSSocket < TCPSocket
|
class SOCKSSocket < TCPSocket
|
||||||
|
# :stopdoc:
|
||||||
alias original_resolv_initialize initialize
|
alias original_resolv_initialize initialize
|
||||||
|
# :startdoc:
|
||||||
def initialize(host, serv)
|
def initialize(host, serv)
|
||||||
original_resolv_initialize(IPSocket.getaddress(host), port)
|
original_resolv_initialize(IPSocket.getaddress(host), port)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue