summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
Diffstat (limited to 'ext')
-rw-r--r--ext/socket/ancdata.c34
-rw-r--r--ext/socket/basicsocket.c6
-rw-r--r--ext/socket/constants.c1
-rw-r--r--ext/socket/ipsocket.c2
-rw-r--r--ext/socket/lib/socket.rb4
-rw-r--r--ext/socket/mkconstants.rb9
-rw-r--r--ext/socket/option.c6
-rw-r--r--ext/socket/rubysocket.h10
-rw-r--r--ext/socket/socket.c14
-rw-r--r--ext/socket/sockssocket.c2
-rw-r--r--ext/socket/tcpserver.c3
-rw-r--r--ext/socket/tcpsocket.c2
-rw-r--r--ext/socket/udpsocket.c2
-rw-r--r--ext/socket/unixserver.c3
-rw-r--r--ext/socket/unixsocket.c2
15 files changed, 62 insertions, 38 deletions
diff --git a/ext/socket/ancdata.c b/ext/socket/ancdata.c
index 370e5b5..11409aa 100644
--- a/ext/socket/ancdata.c
+++ b/ext/socket/ancdata.c
@@ -1325,13 +1325,13 @@ bsock_sendmsg_internal(int argc, VALUE *argv, VALUE sock, int nonblock)
* sock.sendmsg("\0", 0, nil, ancdata)
*
*/
-static VALUE
-bsock_sendmsg(int argc, VALUE *argv, VALUE sock)
+VALUE
+rsock_bsock_sendmsg(int argc, VALUE *argv, VALUE sock)
{
return bsock_sendmsg_internal(argc, argv, sock, 0);
}
#else
-#define bsock_sendmsg rb_f_notimplement
+#define rsock_bsock_sendmsg rb_f_notimplement
#endif
#if defined(HAVE_SENDMSG)
@@ -1346,8 +1346,8 @@ bsock_sendmsg(int argc, VALUE *argv, VALUE sock)
* and it doesn't retry the system call.
*
*/
-static VALUE
-bsock_sendmsg_nonblock(int argc, VALUE *argv, VALUE sock)
+VALUE
+rsock_bsock_sendmsg_nonblock(int argc, VALUE *argv, VALUE sock)
{
return bsock_sendmsg_internal(argc, argv, sock, 1);
}
@@ -1737,13 +1737,13 @@ bsock_recvmsg_internal(int argc, VALUE *argv, VALUE sock, int nonblock)
* }
*
*/
-static VALUE
-bsock_recvmsg(int argc, VALUE *argv, VALUE sock)
+VALUE
+rsock_bsock_recvmsg(int argc, VALUE *argv, VALUE sock)
{
return bsock_recvmsg_internal(argc, argv, sock, 0);
}
#else
-#define bsock_recvmsg rb_f_notimplement
+#define rsock_bsock_recvmsg rb_f_notimplement
#endif
#if defined(HAVE_RECVMSG)
@@ -1758,27 +1758,21 @@ bsock_recvmsg(int argc, VALUE *argv, VALUE sock)
* and it doesn't retry the system call.
*
*/
-static VALUE
-bsock_recvmsg_nonblock(int argc, VALUE *argv, VALUE sock)
+VALUE
+rsock_bsock_recvmsg_nonblock(int argc, VALUE *argv, VALUE sock)
{
return bsock_recvmsg_internal(argc, argv, sock, 1);
}
#else
-#define bsock_recvmsg_nonblock rb_f_notimplement
+#define rsock_bsock_recvmsg_nonblock rb_f_notimplement
#endif
+/*
+ * Document-class: ::Socket::AncillaryData
+ */
void
Init_ancdata(void)
{
- /* for rdoc */
- /* rb_cBasicSocket = rb_define_class("BasicSocket", rb_cIO); */
- /* rb_cSocket = rb_define_class("Socket", rb_cBasicSocket); */
-
- rb_define_method(rb_cBasicSocket, "sendmsg", bsock_sendmsg, -1);
- rb_define_method(rb_cBasicSocket, "sendmsg_nonblock", bsock_sendmsg_nonblock, -1);
- rb_define_method(rb_cBasicSocket, "recvmsg", bsock_recvmsg, -1);
- rb_define_method(rb_cBasicSocket, "recvmsg_nonblock", bsock_recvmsg_nonblock, -1);
-
#if defined(HAVE_ST_MSG_CONTROL)
rb_cAncillaryData = rb_define_class_under(rb_cSocket, "AncillaryData", rb_cObject);
rb_define_method(rb_cAncillaryData, "initialize", ancillary_initialize, 4);
diff --git a/ext/socket/basicsocket.c b/ext/socket/basicsocket.c
index 46253df..440eb76 100644
--- a/ext/socket/basicsocket.c
+++ b/ext/socket/basicsocket.c
@@ -747,4 +747,10 @@ Init_basicsocket(void)
rb_define_method(rb_cBasicSocket, "recv_nonblock", bsock_recv_nonblock, -1);
rb_define_method(rb_cBasicSocket, "do_not_reverse_lookup", bsock_do_not_reverse_lookup, 0);
rb_define_method(rb_cBasicSocket, "do_not_reverse_lookup=", bsock_do_not_reverse_lookup_set, 1);
+
+ rb_define_method(rb_cBasicSocket, "sendmsg", rsock_bsock_sendmsg, -1); /* in ancdata.c */
+ rb_define_method(rb_cBasicSocket, "sendmsg_nonblock", rsock_bsock_sendmsg_nonblock, -1); /* in ancdata.c */
+ rb_define_method(rb_cBasicSocket, "recvmsg", rsock_bsock_recvmsg, -1); /* in ancdata.c */
+ rb_define_method(rb_cBasicSocket, "recvmsg_nonblock", rsock_bsock_recvmsg_nonblock, -1); /* in ancdata.c */
+
}
diff --git a/ext/socket/constants.c b/ext/socket/constants.c
index 4350a12..4fdc40d 100644
--- a/ext/socket/constants.c
+++ b/ext/socket/constants.c
@@ -141,6 +141,5 @@ void
Init_socket_constants(void)
{
/* constants */
- rb_mSockConst = rb_define_module_under(rb_cSocket, "Constants");
init_constants();
}
diff --git a/ext/socket/ipsocket.c b/ext/socket/ipsocket.c
index ee45599..03e6b45 100644
--- a/ext/socket/ipsocket.c
+++ b/ext/socket/ipsocket.c
@@ -284,6 +284,8 @@ ip_s_getaddress(VALUE obj, VALUE host)
}
/*
+ * Document-class: ::IPSocket < BasicSocket
+ *
* IPSocket class
*/
void
diff --git a/ext/socket/lib/socket.rb b/ext/socket/lib/socket.rb
index 5dd5ca6..1ff05b8 100644
--- a/ext/socket/lib/socket.rb
+++ b/ext/socket/lib/socket.rb
@@ -158,7 +158,7 @@ class Addrinfo
end
end
-class BasicSocket
+class BasicSocket < IO
# Returns an address of the socket suitable for connect in the local machine.
#
# This method returns _self_.local_address, except following condition.
@@ -200,7 +200,7 @@ class BasicSocket
end
end
-class Socket
+class Socket < BasicSocket
# enable the socket option IPV6_V6ONLY if IPV6_V6ONLY is available.
def ipv6only!
if defined? Socket::IPV6_V6ONLY
diff --git a/ext/socket/mkconstants.rb b/ext/socket/mkconstants.rb
index 6df8fbe..dbcba25 100644
--- a/ext/socket/mkconstants.rb
+++ b/ext/socket/mkconstants.rb
@@ -83,7 +83,9 @@ EOS
ERB.new(<<'EOS', nil, '%').def_method(Object, "gen_const_defs_in_guard(make_value, name, default_value)")
#if defined(<%=name%>)
+ /* <%=name%>: */
rb_define_const(rb_cSocket, <%=c_str name%>, <%=make_value%>(<%=name%>));
+ /* <%=name%>: */
rb_define_const(rb_mSockConst, <%=c_str name%>, <%=make_value%>(<%=name%>));
#endif
EOS
@@ -272,12 +274,13 @@ result = ERB.new(<<'EOS', nil, '%').result(binding)
<%= INTERN_DEFS.map {|vardef, gen_hash, decl, func| vardef }.join("\n") %>
+/*
+ * Document-module: Socket::Constants
+ */
static void
init_constants(void)
{
- /* for rdoc */
- /* rb_cSocket = rb_define_class("Socket", rb_cBasicSocket); */
- /* rb_mSockConst = rb_define_module_under(rb_cSocket, "Constants"); */
+ rb_mSockConst = rb_define_module_under(rb_cSocket, "Constants");
<%= gen_const_defs %>
<%= INTERN_DEFS.map {|vardef, gen_hash, decl, func| gen_hash }.join("\n") %>
diff --git a/ext/socket/option.c b/ext/socket/option.c
index d1d557d..89265b7 100644
--- a/ext/socket/option.c
+++ b/ext/socket/option.c
@@ -658,12 +658,12 @@ sockopt_unpack(VALUE self, VALUE template)
return rb_funcall(sockopt_data(self), rb_intern("unpack"), 1, template);
}
+/*
+ * Document-class: ::Socket::Option
+ */
void
Init_sockopt(void)
{
- /* for rdoc */
- /* rb_cSocket = rb_define_class("Socket", rb_cBasicSocket); */
-
rb_cSockOpt = rb_define_class_under(rb_cSocket, "Option", rb_cObject);
rb_define_method(rb_cSockOpt, "initialize", sockopt_initialize, 4);
rb_define_method(rb_cSockOpt, "family", sockopt_family_m, 0);
diff --git a/ext/socket/rubysocket.h b/ext/socket/rubysocket.h
index 5164488..2159e74 100644
--- a/ext/socket/rubysocket.h
+++ b/ext/socket/rubysocket.h
@@ -254,9 +254,19 @@ int rsock_connect(int fd, const struct sockaddr *sockaddr, int len, int socks);
VALUE rsock_s_accept(VALUE klass, int fd, struct sockaddr *sockaddr, socklen_t *len);
VALUE rsock_s_accept_nonblock(VALUE klass, rb_io_t *fptr, struct sockaddr *sockaddr, socklen_t *len);
+VALUE rsock_sock_listen(VALUE sock, VALUE log);
VALUE rsock_sockopt_new(int family, int level, int optname, VALUE data);
+#if defined(HAVE_SENDMSG)
+VALUE rsock_bsock_sendmsg(int argc, VALUE *argv, VALUE sock);
+VALUE rsock_bsock_sendmsg_nonblock(int argc, VALUE *argv, VALUE sock);
+#endif
+#if defined(HAVE_RECVMSG)
+VALUE rsock_bsock_recvmsg(int argc, VALUE *argv, VALUE sock);
+VALUE rsock_bsock_recvmsg_nonblock(int argc, VALUE *argv, VALUE sock);
+#endif
+
#ifdef HAVE_ST_MSG_CONTROL
void rsock_discard_cmsg_resource(struct msghdr *mh);
#endif
diff --git a/ext/socket/socket.c b/ext/socket/socket.c
index ab7bd95..819c451 100644
--- a/ext/socket/socket.c
+++ b/ext/socket/socket.c
@@ -485,8 +485,8 @@ sock_bind(VALUE sock, VALUE addr)
* * listen manual pages on unix-based systems
* * listen function in Microsoft's Winsock functions reference
*/
-static VALUE
-sock_listen(VALUE sock, VALUE log)
+VALUE
+rsock_sock_listen(VALUE sock, VALUE log)
{
rb_io_t *fptr;
int backlog;
@@ -1780,6 +1780,8 @@ socket_s_ip_address_list(VALUE self)
#endif
/*
+ * Document-class: ::Socket < BasicSocket
+ *
* Class +Socket+ provides access to the underlying operating system
* socket implementations. It can be used to provide more operating system
* specific functionality than the protocol-specific socket classes but at the
@@ -1817,7 +1819,7 @@ Init_socket()
rb_define_method(rb_cSocket, "connect", sock_connect, 1);
rb_define_method(rb_cSocket, "connect_nonblock", sock_connect_nonblock, 1);
rb_define_method(rb_cSocket, "bind", sock_bind, 1);
- rb_define_method(rb_cSocket, "listen", sock_listen, 1);
+ rb_define_method(rb_cSocket, "listen", rsock_sock_listen, 1);
rb_define_method(rb_cSocket, "accept", sock_accept, 0);
rb_define_method(rb_cSocket, "accept_nonblock", sock_accept_nonblock, 0);
rb_define_method(rb_cSocket, "sysaccept", sock_sysaccept, 0);
@@ -1844,10 +1846,4 @@ Init_socket()
#endif
rb_define_singleton_method(rb_cSocket, "ip_address_list", socket_s_ip_address_list, 0);
-
- /* defined here for rdoc */
- rb_define_method(rb_cTCPServer, "listen", sock_listen, 1);
-#ifdef HAVE_SYS_UN_H
- rb_define_method(rb_cUNIXServer, "listen", sock_listen, 1);
-#endif
}
diff --git a/ext/socket/sockssocket.c b/ext/socket/sockssocket.c
index 71836f7..84397ad 100644
--- a/ext/socket/sockssocket.c
+++ b/ext/socket/sockssocket.c
@@ -41,6 +41,8 @@ socks_s_close(VALUE sock)
#endif
/*
+ * Document-class: ::SOCKSSocket < TCPSocket
+ *
* SOCKSSocket class
*/
void
diff --git a/ext/socket/tcpserver.c b/ext/socket/tcpserver.c
index 59cd7dd..229c2b1 100644
--- a/ext/socket/tcpserver.c
+++ b/ext/socket/tcpserver.c
@@ -129,6 +129,8 @@ tcp_sysaccept(VALUE sock)
}
/*
+ * Document-class: ::TCPServer < TCPSocket
+ *
* TCPServer class
*/
void
@@ -139,4 +141,5 @@ Init_tcpserver(void)
rb_define_method(rb_cTCPServer, "accept_nonblock", tcp_accept_nonblock, 0);
rb_define_method(rb_cTCPServer, "sysaccept", tcp_sysaccept, 0);
rb_define_method(rb_cTCPServer, "initialize", tcp_svr_init, -1);
+ rb_define_method(rb_cTCPServer, "listen", rsock_sock_listen, 1); /* in socket.c */
}
diff --git a/ext/socket/tcpsocket.c b/ext/socket/tcpsocket.c
index 1ab6245..d7164ad 100644
--- a/ext/socket/tcpsocket.c
+++ b/ext/socket/tcpsocket.c
@@ -56,6 +56,8 @@ tcp_s_gethostbyname(VALUE obj, VALUE host)
}
/*
+ * Document-class: ::TCPSocket < IPSocket
+ *
* TCPSocket class
*/
void
diff --git a/ext/socket/udpsocket.c b/ext/socket/udpsocket.c
index 8638d81..3a42e0e 100644
--- a/ext/socket/udpsocket.c
+++ b/ext/socket/udpsocket.c
@@ -247,6 +247,8 @@ udp_recvfrom_nonblock(int argc, VALUE *argv, VALUE sock)
}
/*
+ * Document-class: ::UDPSocket < IPSocket
+ *
* UDPSocket class
*/
void
diff --git a/ext/socket/unixserver.c b/ext/socket/unixserver.c
index fa41cba..e29e9cb 100644
--- a/ext/socket/unixserver.c
+++ b/ext/socket/unixserver.c
@@ -136,6 +136,8 @@ unix_sysaccept(VALUE sock)
#endif
/*
+ * Document-class: ::UNIXServer < UNIXSocket
+ *
* UNIXServer class
*/
void
@@ -147,5 +149,6 @@ Init_unixserver(void)
rb_define_method(rb_cUNIXServer, "accept", unix_accept, 0);
rb_define_method(rb_cUNIXServer, "accept_nonblock", unix_accept_nonblock, 0);
rb_define_method(rb_cUNIXServer, "sysaccept", unix_sysaccept, 0);
+ rb_define_method(rb_cUNIXServer, "listen", rsock_sock_listen, 1); /* in socket.c */
#endif
}
diff --git a/ext/socket/unixsocket.c b/ext/socket/unixsocket.c
index df1a11d..89beb66 100644
--- a/ext/socket/unixsocket.c
+++ b/ext/socket/unixsocket.c
@@ -485,6 +485,8 @@ unix_s_socketpair(int argc, VALUE *argv, VALUE klass)
#endif
/*
+ * Document-class: ::UNIXSocket < BasicSocket
+ *
* UNIXSocket class
*/
void