* Added connection read/write timeout option; default: 60 seconds.
authorUrban Wallasch <urban.wallasch@freenet.de>
Mon, 8 Apr 2019 19:35:05 +0000 (21:35 +0200)
committerUrban Wallasch <urban.wallasch@freenet.de>
Mon, 8 Apr 2019 19:35:05 +0000 (21:35 +0200)
* Support verbose option in configuration files.

README.md
config.go
gogopherd.cfg.example
gogopherd.go

index 299dfa705a5d3432ff714acf70a7d87107573538..7abc92992324d9273b86f91d1b891c1e47387255 100644 (file)
--- 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
 ```
index ddd75230906d9a4a928d802f58ffc562848a5fa7..1ce1ab9e99240061a859f420f63b44d341ca1ba1 100644 (file)
--- 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)
 }
 
index 870fb5c008d8c54d40165365771d9af76751913b..c3d00a4598ebf6f3a1d51646b1cb47c6e389eab5 100644 (file)
@@ -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
index 3ce9678c0c771a5eee90e72650216873b3afacf2..ee37184d0a1cda8d33a702bef794ff5402c31157 100644 (file)
@@ -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