Skip to content

Commit

Permalink
unix: implement recvmsgRaw and sendmsgN on aix
Browse files Browse the repository at this point in the history
This allows using RecvmsgBuffers and SendmsgBuffers on aix in x/net.

For golang/go#54099

Change-Id: Ib21c59244c9d74b826f4fc8ba3314e3602fd9a8a
Reviewed-on: https://go-review.googlesource.com/c/sys/+/419396
Reviewed-by: Cherry Mui <[email protected]>
Reviewed-by: Ian Lance Taylor <[email protected]>
Run-TryBot: Tobias Klauser <[email protected]>
Auto-Submit: Tobias Klauser <[email protected]>
TryBot-Result: Gopher Robot <[email protected]>
  • Loading branch information
tklauser authored and gopherbot committed Jul 28, 2022
1 parent e65921a commit 3c1f352
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 8 deletions.
57 changes: 53 additions & 4 deletions unix/syscall_aix.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,13 +218,62 @@ func Accept(fd int) (nfd int, sa Sockaddr, err error) {
}

func recvmsgRaw(fd int, iov []Iovec, oob []byte, flags int, rsa *RawSockaddrAny) (n, oobn int, recvflags int, err error) {
// Recvmsg not implemented on AIX
return -1, -1, -1, ENOSYS
var msg Msghdr
msg.Name = (*byte)(unsafe.Pointer(rsa))
msg.Namelen = uint32(SizeofSockaddrAny)
var dummy byte
if len(oob) > 0 {
// receive at least one normal byte
if emptyIovecs(iov) {
var iova [1]Iovec
iova[0].Base = &dummy
iova[0].SetLen(1)
iov = iova[:]
}
msg.Control = (*byte)(unsafe.Pointer(&oob[0]))
msg.SetControllen(len(oob))
}
if len(iov) > 0 {
msg.Iov = &iov[0]
msg.SetIovlen(len(iov))
}
if n, err = recvmsg(fd, &msg, flags); n == -1 {
return
}
oobn = int(msg.Controllen)
recvflags = int(msg.Flags)
return
}

func sendmsgN(fd int, iov []Iovec, oob []byte, ptr unsafe.Pointer, salen _Socklen, flags int) (n int, err error) {
// SendmsgN not implemented on AIX
return -1, ENOSYS
var msg Msghdr
msg.Name = (*byte)(unsafe.Pointer(ptr))
msg.Namelen = uint32(salen)
var dummy byte
var empty bool
if len(oob) > 0 {
// send at least one normal byte
empty := emptyIovecs(iov)
if empty {
var iova [1]Iovec
iova[0].Base = &dummy
iova[0].SetLen(1)
iov = iova[:]
}
msg.Control = (*byte)(unsafe.Pointer(&oob[0]))
msg.SetControllen(len(oob))
}
if len(iov) > 0 {
msg.Iov = &iov[0]
msg.SetIovlen(len(iov))
}
if n, err = sendmsg(fd, &msg, flags); err != nil {
return 0, err
}
if len(oob) > 0 && empty {
n = 0
}
return n, nil
}

func anyToSockaddr(fd int, rsa *RawSockaddrAny) (Sockaddr, error) {
Expand Down
4 changes: 0 additions & 4 deletions unix/syscall_unix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -957,10 +957,6 @@ 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)
Expand Down

0 comments on commit 3c1f352

Please sign in to comment.