git » 5medias » commit bdd86e0

Add a flag for the dial timeout

author Alberto Bertogli
2018-07-01 10:50:55 UTC
committer Alberto Bertogli
2018-07-01 10:50:55 UTC
parent a60ae05b9fb3be25ee65fe6e01e80fbb22841134

Add a flag for the dial timeout

For some applications, it can be useful to tweak the dial timeout. This
patch makes it a flag, and reduces the default to 2s.

5medias.go +6 -4

diff --git a/5medias.go b/5medias.go
index 12fb56c..bab4e4e 100644
--- a/5medias.go
+++ b/5medias.go
@@ -24,9 +24,11 @@ import (
 
 // Command-line flags.
 var (
-	addr     = flag.String("addr", ":1080", "address to listen on")
-	username = flag.String("username", "", "username to expect")
-	password = flag.String("password", "", "password to expect")
+	addr        = flag.String("addr", ":1080", "address to listen on")
+	username    = flag.String("username", "", "username to expect")
+	password    = flag.String("password", "", "password to expect")
+	dialTimeout = flag.Duration("dial_timeout", 2*time.Second,
+		"timeout for establishing outgoing connections")
 
 	allowLoopback = flag.Bool("allow_loopback", false,
 		"allow loopback connections")
@@ -80,7 +82,7 @@ func (c *Conn) Handle() {
 	}
 
 	c.Logf("dial %q", dstAddr)
-	dstConn, err := net.DialTimeout("tcp", dstAddr, 10*time.Second)
+	dstConn, err := net.DialTimeout("tcp", dstAddr, *dialTimeout)
 	if err != nil {
 		c.Logf("outgoing connection error: %v", err)
 		c.reply(5) // Connection refused.