Skip to content

Commit

Permalink
changed Dial to DialTimeout and set 250ms as default timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
Oleg Gerasimenko committed Apr 6, 2016
1 parent acf6efb commit 812b38f
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ import (
"io"
"log"
"net"
"time"
)

type stringSlice []string

var timeOutDuration time.Duration

func (s *stringSlice) String() string {
return fmt.Sprintf("%v", *s)
}
Expand All @@ -24,7 +27,7 @@ func proxyConnection(conn net.Conn, destinations stringSlice) {
var upstreamConns []io.Writer

for _, addr := range destinations {
forwardConn, err := net.Dial("tcp", addr)
forwardConn, err := net.DialTimeout("tcp", addr, timeOutDuration)
if err != nil {
log.Println(err)
continue
Expand Down Expand Up @@ -66,6 +69,7 @@ func main() {

flag.StringVar(&source, "s", "", "Host to listen on")
flag.Var(&destinations, "d", "List of destination hosts")
flag.DurationVar(&timeOutDuration, "t", 250*time.Millisecond, "Timeout for connecting to the destination")
flag.Parse()

if flag.NFlag() < 2 {
Expand Down

0 comments on commit 812b38f

Please sign in to comment.