summaryrefslogtreecommitdiff
path: root/sample/tsvr.rb
diff options
context:
space:
mode:
Diffstat (limited to 'sample/tsvr.rb')
-rw-r--r--sample/tsvr.rb7
1 files changed, 2 insertions, 5 deletions
diff --git a/sample/tsvr.rb b/sample/tsvr.rb
index d6a5620d114..ebfad4beeb6 100644
--- a/sample/tsvr.rb
+++ b/sample/tsvr.rb
@@ -2,7 +2,6 @@
# usage: ruby tsvr.rb
require "socket"
-require "thread"
gs = TCPserver.open(0)
addr = gs.addr
@@ -10,10 +9,8 @@ addr.shift
printf("server is on %d\n", addr.join(":"))
while TRUE
- ns = gs.accept
- print(ns, " is accepted\n")
- Thread.start do
- s = ns # save to thread-local variable
+ Thread.start(gs.accept) do |s|
+ print(s, " is accepted\n")
while s.gets
s.write($_)
end