summaryrefslogtreecommitdiff
path: root/ext/socket/tcpserver.c
diff options
context:
space:
mode:
authordrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-08-15 23:08:39 +0000
committerdrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-08-15 23:08:39 +0000
commit12979424515344460afb12002ce07b670bf7cd6f (patch)
tree2d85f664a0fb708e459a30c56738487948ced8f9 /ext/socket/tcpserver.c
parent39e112f89a4e7471bb95ec516b05c75ac6df5aa9 (diff)
* ext/socket: Make Socket documentation appear. Add documentation for
Socket, TCPServer, SOCKSSocket. Patch by Sylvain Daubert. [Ruby 1.9 - Feature #5182] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32977 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/socket/tcpserver.c')
-rw-r--r--ext/socket/tcpserver.c36
1 files changed, 31 insertions, 5 deletions
diff --git a/ext/socket/tcpserver.c b/ext/socket/tcpserver.c
index 7bb02d9..6596733 100644
--- a/ext/socket/tcpserver.c
+++ b/ext/socket/tcpserver.c
@@ -128,14 +128,40 @@ tcp_sysaccept(VALUE sock)
return rsock_s_accept(0, fptr->fd, (struct sockaddr*)&from, &fromlen);
}
-/*
- * Document-class: ::TCPServer < TCPSocket
- *
- * TCPServer represents a TCP/IP server socket.
- */
void
rsock_init_tcpserver(void)
{
+ /*
+ * Document-class: TCPServer < TCPSocket
+ *
+ * TCPServer represents a TCP/IP server socket.
+ *
+ * A simple TCP server may look like:
+ *
+ * require 'socket'
+ *
+ * server = TCPServer.new 2000 # Server bind to port 2000
+ * loop do
+ * client = server.accept # Wait for a client to connect
+ * client.puts "Hello !"
+ * client.puts "Time is #{Time.now}"
+ * client.close
+ * end
+ *
+ * A more usable server (serving multiple clients):
+ *
+ * require 'socket'
+ *
+ * server = TCPServer.new 2000
+ * loop do
+ * Thread.start(server.accept) do |client|
+ * client.puts "Hello !"
+ * client.puts "Time is #{Time.now}"
+ * client.close
+ * end
+ * end
+ *
+ */
rb_cTCPServer = rb_define_class("TCPServer", rb_cTCPSocket);
rb_define_method(rb_cTCPServer, "accept", tcp_accept, 0);
rb_define_method(rb_cTCPServer, "accept_nonblock", tcp_accept_nonblock, 0);