summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-03-22 03:33:14 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-03-22 03:33:14 +0000
commit1561d3fb8b2eb8bfeaabd1d05ff0870b285feb4e (patch)
tree4e43d3d7cf65be3bfac6de15198195891f647e25
parent1a40be09d635c4b35008877c3fdf10c963e08641 (diff)
update doc.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27009 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ext/socket/basicsocket.c4
-rw-r--r--ext/socket/ipsocket.c2
-rw-r--r--ext/socket/socket.c13
-rw-r--r--lib/resolv-replace.rb12
4 files changed, 30 insertions, 1 deletions
diff --git a/ext/socket/basicsocket.c b/ext/socket/basicsocket.c
index 440eb76e2e..5e28bcf956 100644
--- a/ext/socket/basicsocket.c
+++ b/ext/socket/basicsocket.c
@@ -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)
diff --git a/ext/socket/ipsocket.c b/ext/socket/ipsocket.c
index 03e6b4518e..ad1ac231c3 100644
--- a/ext/socket/ipsocket.c
+++ b/ext/socket/ipsocket.c
@@ -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"
diff --git a/ext/socket/socket.c b/ext/socket/socket.c
index b9192285c2..1b026a6741 100644
--- a/ext/socket/socket.c
+++ b/ext/socket/socket.c
@@ -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
diff --git a/lib/resolv-replace.rb b/lib/resolv-replace.rb
index 091b961f4f..b63eae8f02 100644
--- a/lib/resolv-replace.rb
+++ b/lib/resolv-replace.rb
@@ -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