mirror of
https://github.com/rwinkhart/sys.git
synced 2026-09-03 15:47:35 -04:00
unix: add RecvmsgBuffers and SendmsgBuffers
Fixes golang/go#52885 Change-Id: I04b5be1ac9543a3791ebc4cd59b9e35e958e0ba2 Reviewed-on: https://go-review.googlesource.com/c/sys/+/412497 Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com> Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Carlos Amedee <carlos@golang.org> Auto-Submit: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Ian Lance Taylor <iant@google.com>
This commit is contained in:
committed by
Gopher Robot
parent
175b2fd9d6
commit
87e55d7148
@@ -16,8 +16,10 @@ import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"sync"
|
||||
"syscall"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -954,6 +956,68 @@ func TestSend(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestSendmsgBuffers(t *testing.T) {
|
||||
if runtime.GOOS == "aix" {
|
||||
t.Skipf("SendmsgBuffers not supported on %s", runtime.GOOS)
|
||||
}
|
||||
|
||||
fds, err := unix.Socketpair(unix.AF_LOCAL, unix.SOCK_STREAM, 0)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer unix.Close(fds[0])
|
||||
defer unix.Close(fds[1])
|
||||
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
bufs := [][]byte{
|
||||
make([]byte, 5),
|
||||
nil,
|
||||
make([]byte, 5),
|
||||
}
|
||||
n, oobn, recvflags, _, err := unix.RecvmsgBuffers(fds[1], bufs, nil, 0)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if n != 10 {
|
||||
t.Errorf("got %d bytes, want 10", n)
|
||||
}
|
||||
if oobn != 0 {
|
||||
t.Errorf("got %d OOB bytes, want 0", oobn)
|
||||
}
|
||||
if recvflags != 0 {
|
||||
t.Errorf("got flags %#x, want %#x", recvflags, 0)
|
||||
}
|
||||
want := [][]byte{
|
||||
[]byte("01234"),
|
||||
nil,
|
||||
[]byte("56789"),
|
||||
}
|
||||
if !reflect.DeepEqual(bufs, want) {
|
||||
t.Errorf("got data %q, want %q", bufs, want)
|
||||
}
|
||||
}()
|
||||
|
||||
defer wg.Wait()
|
||||
|
||||
bufs := [][]byte{
|
||||
[]byte("012"),
|
||||
[]byte("34"),
|
||||
nil,
|
||||
[]byte("5678"),
|
||||
[]byte("9"),
|
||||
}
|
||||
n, err := unix.SendmsgBuffers(fds[0], bufs, nil, nil, 0)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if n != 10 {
|
||||
t.Errorf("sent %d bytes, want 10", n)
|
||||
}
|
||||
}
|
||||
|
||||
// mktmpfifo creates a temporary FIFO and provides a cleanup function.
|
||||
func mktmpfifo(t *testing.T) (*os.File, func()) {
|
||||
err := unix.Mkfifo("fifo", 0666)
|
||||
|
||||
Reference in New Issue
Block a user