-
Notifications
You must be signed in to change notification settings - Fork 67
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
1 parent
e5825dc
commit 2fa0399
Showing
2 changed files
with
40 additions
and
0 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,29 @@ | ||
package control | ||
|
||
import ( | ||
"syscall" | ||
"time" | ||
_ "unsafe" | ||
|
||
E "github.com/sagernet/sing/common/exceptions" | ||
N "github.com/sagernet/sing/common/network" | ||
|
||
"golang.org/x/sys/unix" | ||
) | ||
|
||
func SetKeepAlivePeriod(idle time.Duration, interval time.Duration) Func { | ||
return func(network, address string, conn syscall.RawConn) error { | ||
if N.NetworkName(network) != N.NetworkTCP { | ||
return nil | ||
} | ||
return Raw(conn, func(fd uintptr) error { | ||
return E.Errors( | ||
unix.SetsockoptInt(int(fd), unix.IPPROTO_TCP, unix.TCP_KEEPIDLE, int(roundDurationUp(idle, time.Second))), | ||
unix.SetsockoptInt(int(fd), unix.IPPROTO_TCP, unix.TCP_KEEPINTVL, int(roundDurationUp(interval, time.Second))), | ||
) | ||
}) | ||
} | ||
} | ||
|
||
//go:linkname roundDurationUp net.roundDurationUp | ||
func roundDurationUp(d time.Duration, to time.Duration) time.Duration |
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,11 @@ | ||
//go:build !linux | ||
|
||
package control | ||
|
||
import ( | ||
"time" | ||
) | ||
|
||
func SetKeepAlivePeriod(idle time.Duration, interval time.Duration) Func { | ||
return nil | ||
} |