Commit 68c10286 authored by Jason A. Donenfeld's avatar Jason A. Donenfeld Committed by Brad Fitzpatrick

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/108338Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent 1c439e6e
...@@ -541,15 +541,17 @@ func Recvmsg(fd int, p, oob []byte, flags int) (n, oobn int, recvflags int, from ...@@ -541,15 +541,17 @@ func Recvmsg(fd int, p, oob []byte, flags int) (n, oobn int, recvflags int, from
} }
var dummy byte var dummy byte
if len(oob) > 0 { if len(oob) > 0 {
var sockType int if len(p) == 0 {
sockType, err = GetsockoptInt(fd, SOL_SOCKET, SO_TYPE) var sockType int
if err != nil { sockType, err = GetsockoptInt(fd, SOL_SOCKET, SO_TYPE)
return if err != nil {
} return
// receive at least one normal byte }
if sockType != SOCK_DGRAM && len(p) == 0 { // receive at least one normal byte
iov.Base = &dummy if sockType != SOCK_DGRAM {
iov.SetLen(1) iov.Base = &dummy
iov.SetLen(1)
}
} }
msg.Control = &oob[0] msg.Control = &oob[0]
msg.SetControllen(len(oob)) msg.SetControllen(len(oob))
...@@ -593,15 +595,17 @@ func SendmsgN(fd int, p, oob []byte, to Sockaddr, flags int) (n int, err error) ...@@ -593,15 +595,17 @@ func SendmsgN(fd int, p, oob []byte, to Sockaddr, flags int) (n int, err error)
} }
var dummy byte var dummy byte
if len(oob) > 0 { if len(oob) > 0 {
var sockType int if len(p) == 0 {
sockType, err = GetsockoptInt(fd, SOL_SOCKET, SO_TYPE) var sockType int
if err != nil { sockType, err = GetsockoptInt(fd, SOL_SOCKET, SO_TYPE)
return 0, err if err != nil {
} return 0, err
// send at least one normal byte }
if sockType != SOCK_DGRAM && len(p) == 0 { // send at least one normal byte
iov.Base = &dummy if sockType != SOCK_DGRAM {
iov.SetLen(1) iov.Base = &dummy
iov.SetLen(1)
}
} }
msg.Control = &oob[0] msg.Control = &oob[0]
msg.SetControllen(len(oob)) msg.SetControllen(len(oob))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment