aboutsummaryrefslogtreecommitdiff
path: root/src/syscall/syscall_linux.go
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2018-04-19 23:46:52 +0200
committerBrad Fitzpatrick <bradfitz@golang.org>2018-04-19 22:16:24 +0000
commit68c10286c795e286c3efaa7df6d52d12af446d57 (patch)
treedb549f58c987a30f011c1f7247eee934b85bf298 /src/syscall/syscall_linux.go
parent1c439e6e37c87c9543cb1860c3b8d174658b80ca (diff)
downloadgo-68c10286c795e286c3efaa7df6d52d12af446d57.tar.xz
syscall: avoid extra syscall on send/recvmsg on Linux
By simply rearranging the logic, we avoid the overhead of a superfluous call to getsockopt. For, if p is already non empty, there's no point in having to check if we need to attach dummy payload. This has performance benefits when using send/recvmsg for high speed communications. Change-Id: Id85cff17328ecbf6d09dd52fbeeaa691dbe69b75 Reviewed-on: https://go-review.googlesource.com/108338 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/syscall/syscall_linux.go')
-rw-r--r--src/syscall/syscall_linux.go40
1 files changed, 22 insertions, 18 deletions
diff --git a/src/syscall/syscall_linux.go b/src/syscall/syscall_linux.go
index 76afab0bfc..2d2863690d 100644
--- a/src/syscall/syscall_linux.go
+++ b/src/syscall/syscall_linux.go
@@ -541,15 +541,17 @@ func Recvmsg(fd int, p, oob []byte, flags int) (n, oobn int, recvflags int, from
}
var dummy byte
if len(oob) > 0 {
- var sockType int
- sockType, err = GetsockoptInt(fd, SOL_SOCKET, SO_TYPE)
- if err != nil {
- return
- }
- // receive at least one normal byte
- if sockType != SOCK_DGRAM && len(p) == 0 {
- iov.Base = &dummy
- iov.SetLen(1)
+ if len(p) == 0 {
+ var sockType int
+ sockType, err = GetsockoptInt(fd, SOL_SOCKET, SO_TYPE)
+ if err != nil {
+ return
+ }
+ // receive at least one normal byte
+ if sockType != SOCK_DGRAM {
+ iov.Base = &dummy
+ iov.SetLen(1)
+ }
}
msg.Control = &oob[0]
msg.SetControllen(len(oob))
@@ -593,15 +595,17 @@ func SendmsgN(fd int, p, oob []byte, to Sockaddr, flags int) (n int, err error)
}
var dummy byte
if len(oob) > 0 {
- var sockType int
- sockType, err = GetsockoptInt(fd, SOL_SOCKET, SO_TYPE)
- if err != nil {
- return 0, err
- }
- // send at least one normal byte
- if sockType != SOCK_DGRAM && len(p) == 0 {
- iov.Base = &dummy
- iov.SetLen(1)
+ if len(p) == 0 {
+ var sockType int
+ sockType, err = GetsockoptInt(fd, SOL_SOCKET, SO_TYPE)
+ if err != nil {
+ return 0, err
+ }
+ // send at least one normal byte
+ if sockType != SOCK_DGRAM {
+ iov.Base = &dummy
+ iov.SetLen(1)
+ }
}
msg.Control = &oob[0]
msg.SetControllen(len(oob))