-
Notifications
You must be signed in to change notification settings - Fork 309
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
53 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright (C) 2017 Michał Matczuk | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
// +build !windows | ||
|
||
package tunnel | ||
|
||
import ( | ||
"net" | ||
"time" | ||
|
||
"github.com/felixge/tcpkeepalive" | ||
) | ||
|
||
var ( | ||
// DefaultKeepAliveIdleTime specifies how long connection can be idle | ||
// before sending keepalive message. | ||
DefaultKeepAliveIdleTime = 15 * time.Minute | ||
// DefaultKeepAliveCount specifies maximal number of keepalive messages | ||
// sent before marking connection as dead. | ||
DefaultKeepAliveCount = 8 | ||
// DefaultKeepAliveInterval specifies how often retry sending keepalive | ||
// messages when no response is received. | ||
DefaultKeepAliveInterval = 5 * time.Second | ||
) | ||
|
||
func keepAlive(conn net.Conn) error { | ||
return tcpkeepalive.SetKeepAlive(conn, DefaultKeepAliveIdleTime, DefaultKeepAliveCount, DefaultKeepAliveInterval) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Copyright (C) 2017 Michał Matczuk | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package tunnel | ||
|
||
import ( | ||
"fmt" | ||
"net" | ||
) | ||
|
||
func keepAlive(conn net.Conn) error { | ||
c, ok := conn.(*net.TCPConn) | ||
if !ok { | ||
return fmt.Errorf("Bad connection type: %T", c) | ||
} | ||
|
||
if err := c.SetKeepAlive(true); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters