diff options
author | yugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-08-25 15:13:14 +0000 |
---|---|---|
committer | yugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-08-25 15:13:14 +0000 |
commit | d0233291bc8a5068e52c69c210e5979e5324b5bc (patch) | |
tree | 7d9459449c33792c63eeb7baa071e76352e0baab /trunk/sample/dualstack-httpd.rb | |
parent | 0dc342de848a642ecce8db697b8fecd83a63e117 (diff) | |
parent | 72eaacaa15256ab95c3b52ea386f88586fb9da40 (diff) |
re-adding tag v1_9_0_4 as an alias of trunk@18848v1_9_0_4
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/tags/v1_9_0_4@18849 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'trunk/sample/dualstack-httpd.rb')
-rw-r--r-- | trunk/sample/dualstack-httpd.rb | 55 |
1 files changed, 0 insertions, 55 deletions
diff --git a/trunk/sample/dualstack-httpd.rb b/trunk/sample/dualstack-httpd.rb deleted file mode 100644 index 69e3181863..0000000000 --- a/trunk/sample/dualstack-httpd.rb +++ /dev/null @@ -1,55 +0,0 @@ -# simple httpd - -# The code demonstrates how a multi-protocol daemon should be written. - -require "socket" -require "thread" - -port = 8888 -res = Socket.getaddrinfo(nil, port, nil, Socket::SOCK_STREAM, nil, Socket::AI_PASSIVE) -sockpool = [] -names = [] -threads = [] - -res.each do |i| - s = TCPserver.new(i[3], i[1]) - n = Socket.getnameinfo(s.getsockname, Socket::NI_NUMERICHOST|Socket::NI_NUMERICSERV).join(" port ") - sockpool.push s - names.push n -end - -(0 .. sockpool.size - 1).each do |i| - mysock = sockpool[i] - myname = names[i] - STDERR.print "socket #{mysock} started, address #{myname}\n" - threads[i] = Thread.start do # Thread.start cannot be used here! - ls = mysock # copy to dynamic variable - t = Thread.current - STDERR.print "socket #{myname} listener started, pid #{$$} thread #{t}\n" - while true - as = ls.accept - Thread.start do - STDERR.print "socket #{myname} accepted, thread ", Thread.current, "\n" - s = as # copy to dynamic variable - str = '' - while line = s.gets - break if line == "\r\n" or line == "\n" - str << line - end - STDERR.print "socket #{myname} got string\n" - s.write("HTTP/1.0 200 OK\n") - s.write("Content-type: text/plain\n\n") - s.write("this is test: my name is #{myname}, you sent:\n") - s.write("---start\n") - s.write(str) - s.write("---end\n") - s.close - STDERR.print "socket #{myname} processed, thread ", Thread.current, " terminating\n" - end - end - end -end - -for t in threads - t.join -end |