From: Urban Wallasch Date: Mon, 8 Apr 2019 19:35:05 +0000 (+0200) Subject: * Added connection read/write timeout option; default: 60 seconds. X-Git-Url: https://git.packet-gain.de/?a=commitdiff_plain;h=3ffc3f98749b3834ad50e57508926910d33ed13b;p=gogopherd.git * Added connection read/write timeout option; default: 60 seconds. * Support verbose option in configuration files. --- diff --git a/README.md b/README.md index 299dfa7..7abc929 100644 --- a/README.md +++ b/README.md @@ -71,6 +71,9 @@ options: -s follow symbolic links + -t int + connection read/write timeout in seconds (default 60) + -v produce verbose output ``` diff --git a/config.go b/config.go index ddd7523..1ce1ab9 100644 --- a/config.go +++ b/config.go @@ -15,6 +15,7 @@ import ( "os" "path" "path/filepath" + "strconv" "strings" ) @@ -29,6 +30,7 @@ var cfg = struct { fsymln bool showdot bool indexes bool + timeout int verbose bool }{ iface: "localhost", @@ -41,6 +43,7 @@ var cfg = struct { fsymln: false, showdot: false, indexes: false, + timeout: 60, verbose: false, } @@ -82,6 +85,10 @@ func parseConfigFile(filename string) error { cfg.showdot = strToBool(val) case "indexes": cfg.indexes = strToBool(val) + case "timeout": + cfg.timeout, _ = strconv.Atoi(val) + case "verbose": + cfg.verbose = strToBool(val) default: logger.Print("ignoring unknown config item: ", name) } @@ -103,7 +110,8 @@ func initialize() { flag.BoolVar(&help, "h", help, "show this help page") flag.BoolVar(&cfg.fsymln, "s", cfg.fsymln, "follow symbolic links") flag.BoolVar(&cfg.showdot, "d", cfg.showdot, "allow access to dotfiles") - flag.BoolVar(&cfg.indexes, "l", cfg.indexes, "allow directory listings") + flag.BoolVar(&cfg.indexes, "l", cfg.indexes, "allow generated directory indexes") + flag.IntVar(&cfg.timeout, "t", cfg.timeout, "connection read/write timeout in seconds") flag.BoolVar(&cfg.verbose, "v", cfg.verbose, "produce verbose output") flag.Parse() if help { @@ -148,6 +156,7 @@ func initialize() { tracer.Print("fsymln: ", cfg.fsymln) tracer.Print("showdot: ", cfg.showdot) tracer.Print("indexes: ", cfg.indexes) + tracer.Print("timeout: ", cfg.timeout) tracer.Print("verbose: ", cfg.verbose) } diff --git a/gogopherd.cfg.example b/gogopherd.cfg.example index 870fb5c..c3d00a4 100644 --- a/gogopherd.cfg.example +++ b/gogopherd.cfg.example @@ -24,4 +24,10 @@ showdot = false # If true, generate directory listings where no index file is found. indexes = true +# Connection read and write timeout in seconds +timeout = 60 + +# Produce verbose output +verbose = false + # EOF diff --git a/gogopherd.go b/gogopherd.go index 3ce9678..ee37184 100644 --- a/gogopherd.go +++ b/gogopherd.go @@ -23,6 +23,7 @@ import ( "path/filepath" "strings" "syscall" + "time" ) var shutting_down bool = false @@ -167,6 +168,7 @@ func sendError(conn net.Conn, msg string) { func handleRequest(conn net.Conn) { defer conn.Close() // get request + conn.SetDeadline(time.Now().Add(time.Duration(cfg.timeout) * time.Second)) req, err := bufio.NewReader(conn).ReadString('\n') if check(err, "ReadString") != nil { return