-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ManipHttp: Add client TCP_USERTIMEOUT option to the socket. (#121)
* ManipHttp: Add client TCP_USERTIMEOUT option to the socket. * Turn off the socketOption by default. * Fix review comments. * Fix lint. * Fix UT. * Add UT. * Add random port and fix review. * Fix typos.
- Loading branch information
1 parent
14e7e30
commit 767644a
Showing
9 changed files
with
205 additions
and
9 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// +build linux | ||
|
||
package syscall | ||
|
||
// package to set to the low-level/OS settings | ||
|
||
import ( | ||
"os" | ||
"syscall" | ||
"time" | ||
|
||
"golang.org/x/sys/unix" | ||
) | ||
|
||
// MakeDialerControlFunc creates a custom control for the dailer | ||
func MakeDialerControlFunc(t time.Duration) func(string, string, syscall.RawConn) error { | ||
// return if the tcpUserTimeout is not set. | ||
if t == 0 { | ||
return nil | ||
} | ||
|
||
return func(network, address string, c syscall.RawConn) error { | ||
var sysErr error | ||
err := c.Control(func(fd uintptr) { | ||
sysErr = syscall.SetsockoptInt(int(fd), syscall.SOL_TCP, unix.TCP_USER_TIMEOUT, | ||
int(t.Milliseconds())) | ||
}) | ||
if sysErr != nil { | ||
return os.NewSyscallError("setsockopt", sysErr) | ||
} | ||
return err | ||
} | ||
} |
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,15 @@ | ||
// +build !linux | ||
|
||
package syscall | ||
|
||
import ( | ||
"syscall" | ||
"time" | ||
) | ||
|
||
// package to set to the low-level/OS settings | ||
|
||
// MakeDialerControlFunc creates a custom control for the dailer | ||
func MakeDialerControlFunc(d time.Duration) func(string, string, syscall.RawConn) error { | ||
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
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
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