mirror of
https://github.com/ksherlock/gopher.git
synced 2024-12-21 21:29:19 +00:00
set root dir on command line.
This commit is contained in:
parent
a0f7de1c2e
commit
c7de9deff1
@ -1,5 +1,10 @@
|
|||||||
#!/usr/bin/env ruby -w
|
#!/usr/bin/env ruby -w
|
||||||
|
|
||||||
|
#
|
||||||
|
# gopher-server [-p port] [root directory]
|
||||||
|
#
|
||||||
|
#
|
||||||
|
|
||||||
require 'socket'
|
require 'socket'
|
||||||
require 'optparse'
|
require 'optparse'
|
||||||
|
|
||||||
@ -125,7 +130,7 @@ port = 7070
|
|||||||
|
|
||||||
OptionParser.new { |opts|
|
OptionParser.new { |opts|
|
||||||
|
|
||||||
opts.banner = "Usage: gopher-server [-p port]"
|
opts.banner = "Usage: gopher-server [-p port] [root-directory]"
|
||||||
|
|
||||||
opts.on('-p P', '--port P', Integer, 'Port') do |x|
|
opts.on('-p P', '--port P', Integer, 'Port') do |x|
|
||||||
port = x
|
port = x
|
||||||
@ -141,7 +146,10 @@ OptionParser.new { |opts|
|
|||||||
}.parse!
|
}.parse!
|
||||||
|
|
||||||
|
|
||||||
|
Dir.chdir(ARGV.pop()) if ARGV.length == 1
|
||||||
|
|
||||||
server = TCPServer.new("0.0.0.0", port)
|
server = TCPServer.new("0.0.0.0", port)
|
||||||
|
puts("Listening on port #{port}")
|
||||||
loop do
|
loop do
|
||||||
Thread.start(server.accept) do |client|
|
Thread.start(server.accept) do |client|
|
||||||
begin
|
begin
|
||||||
@ -152,7 +160,7 @@ loop do
|
|||||||
Thread.current[:hostname] = hostname
|
Thread.current[:hostname] = hostname
|
||||||
Thread.current[:port] = port
|
Thread.current[:port] = port
|
||||||
|
|
||||||
puts("accept from #{addr.join(' ')}")
|
puts("accept from #{peer}")
|
||||||
|
|
||||||
do_request(client)
|
do_request(client)
|
||||||
client.flush()
|
client.flush()
|
||||||
|
Loading…
Reference in New Issue
Block a user