Skip to content

Commit

Permalink
add tcp keep-alived (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
DuckSoft authored Mar 14, 2021
1 parent 92ace24 commit 04bf6df
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions dispatcher/tcp/tcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ func (d *TCP) handleConn(conn net.Conn) error {
userContext *config.UserContext
)
defer conn.Close()
_ = conn.(*net.TCPConn).SetKeepAlive(true)

var data = pool.Get(BasicLen)
defer pool.Put(data)
Expand Down Expand Up @@ -109,6 +110,7 @@ func (d *TCP) handleConn(conn net.Conn) error {
if err != nil {
return fmt.Errorf("[tcp] handleConn dial error: %w", err)
}
_ = rc.(*net.TCPConn).SetKeepAlive(true)

_ = rc.SetDeadline(time.Now().Add(DefaultTimeout))
_, err = rc.Write(data[:n])
Expand Down

0 comments on commit 04bf6df

Please sign in to comment.