Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Dieterbe committed Oct 22, 2018
1 parent b2b41c3 commit b59f518
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
4 changes: 1 addition & 3 deletions input/init.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package input

import (
"io"
)
import "io"

type Plugin interface {
Name() string
Expand Down
2 changes: 1 addition & 1 deletion input/listen.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func (l *Listener) acceptTcpConn(c net.Conn) {
}
}()

l.handler.Handle(c)
l.handler.Handle(NewTimeoutConn(c, 2*time.Minute))
c.Close()
}

Expand Down
24 changes: 24 additions & 0 deletions input/timeout_conn.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package input

import (
"net"
"time"
)

// TimeoutConn automatically applies a read deadline on a conn upon every read
type TimeoutConn struct {
conn net.Conn
timeout time.Duration
}

func NewTimeoutConn(conn net.Conn, timeout time.Duration) TimeoutConn {
return TimeoutConn{
conn: conn,
timeout: timeout,
}
}

func (t TimeoutConn) Read(p []byte) (n int, err error) {
t.conn.SetReadDeadline(time.Now().Add(2 * time.Minute))
return t.conn.Read(p)
}

0 comments on commit b59f518

Please sign in to comment.