mirror of
https://github.com/ruby/ruby.git
synced 2025-09-15 08:33:58 +02:00
Synchronize MANIFEST with reality. Add missing files.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1463 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
32513e9dce
commit
a5d64434dd
5 changed files with 584 additions and 47 deletions
48
sample/dualstack-fetch.rb
Normal file
48
sample/dualstack-fetch.rb
Normal file
|
@ -0,0 +1,48 @@
|
|||
# simple webpage fetcher
|
||||
|
||||
# The code demonstrates how a multi-protocol client should be written.
|
||||
# TCPsocket is using getaddrinfo() internally, so there should be no problem.
|
||||
|
||||
require "socket"
|
||||
|
||||
if ARGV.size != 1
|
||||
STDERR.print "requires URL\n"
|
||||
exit
|
||||
end
|
||||
|
||||
url = ARGV[0]
|
||||
if url !~ /^http:\/\/([^\/]+)(\/.*)$/
|
||||
STDERR.print "only http with full hostname is supported\n"
|
||||
exit
|
||||
end
|
||||
|
||||
# split URL into host, port and path
|
||||
hostport = $1
|
||||
path = $2
|
||||
if (hostport =~ /^(.*):([0-9]+)$/)
|
||||
host = $1
|
||||
port = $2
|
||||
else
|
||||
host = hostport
|
||||
port = 80
|
||||
end
|
||||
if host =~ /^\[(.*)\]$/
|
||||
host = $1
|
||||
end
|
||||
|
||||
#STDERR.print "url=<#{ARGV[0]}>\n"
|
||||
#STDERR.print "host=<#{host}>\n"
|
||||
#STDERR.print "port=<#{port}>\n"
|
||||
#STDERR.print "path=<#{path}>\n"
|
||||
|
||||
STDERR.print "conntecting to #{host} port #{port}\n"
|
||||
c = TCPsocket.new(host, port)
|
||||
dest = Socket.getnameinfo(c.getpeername,
|
||||
Socket::NI_NUMERICHOST|Socket::NI_NUMERICSERV)
|
||||
STDERR.print "conntected to #{dest[0]} port #{dest[1]}\n"
|
||||
c.print "GET #{path} HTTP/1.0\n"
|
||||
c.print "Host: #{host}\n"
|
||||
c.print "\n"
|
||||
while c.gets
|
||||
print
|
||||
end
|
55
sample/dualstack-httpd.rb
Normal file
55
sample/dualstack-httpd.rb
Normal file
|
@ -0,0 +1,55 @@
|
|||
# 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
|
44
sample/io.rb
44
sample/io.rb
|
@ -1,44 +0,0 @@
|
|||
# IO test
|
||||
# usage: ruby io.rb file..
|
||||
|
||||
home = ENV["HOME"]
|
||||
home.sub("m", "&&")
|
||||
print(home, "\n")
|
||||
print(home.reverse, "\n")
|
||||
|
||||
if File.s("io.rb")
|
||||
print(File.s("io.rb"), ": io.rb\n")
|
||||
end
|
||||
|
||||
$/="f\n"
|
||||
for i in "abc\n\ndef\nghi\n"
|
||||
print("tt: ", i)
|
||||
end
|
||||
|
||||
printf("%s:(%d)%s\n", $0, ARGV.length, ARGV[0])
|
||||
passwd = open(ARGV[0], "r")
|
||||
#printf("%s", passwd.find{i|i =~ /\*/})
|
||||
|
||||
n = 1
|
||||
for i in passwd #.grep(/^\*/)
|
||||
printf("%6d: %s", n, i)
|
||||
n = n + 1;
|
||||
end
|
||||
|
||||
fp = open("|-", "r")
|
||||
|
||||
if fp == nil
|
||||
for i in 1..5
|
||||
print(i, "\n")
|
||||
end
|
||||
else
|
||||
for line in fp
|
||||
print(line)
|
||||
end
|
||||
end
|
||||
|
||||
def printUsage()
|
||||
if $USAGE
|
||||
apply($USAGE);
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue