golang.org/x/net@v0.25.1-0.20240516223405-c87a5b62e243/internal/socket/rawconn_msg.go (about)

     1  // Copyright 2017 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  //go:build aix || darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris || windows || zos
     6  
     7  package socket
     8  
     9  import (
    10  	"net"
    11  	"os"
    12  )
    13  
    14  func (c *Conn) recvMsg(m *Message, flags int) error {
    15  	m.raceWrite()
    16  	var (
    17  		operr     error
    18  		n         int
    19  		oobn      int
    20  		recvflags int
    21  		from      net.Addr
    22  	)
    23  	fn := func(s uintptr) bool {
    24  		n, oobn, recvflags, from, operr = recvmsg(s, m.Buffers, m.OOB, flags, c.network)
    25  		return ioComplete(flags, operr)
    26  	}
    27  	if err := c.c.Read(fn); err != nil {
    28  		return err
    29  	}
    30  	if operr != nil {
    31  		return os.NewSyscallError("recvmsg", operr)
    32  	}
    33  	m.Addr = from
    34  	m.N = n
    35  	m.NN = oobn
    36  	m.Flags = recvflags
    37  	return nil
    38  }
    39  
    40  func (c *Conn) sendMsg(m *Message, flags int) error {
    41  	m.raceRead()
    42  	var (
    43  		operr error
    44  		n     int
    45  	)
    46  	fn := func(s uintptr) bool {
    47  		n, operr = sendmsg(s, m.Buffers, m.OOB, m.Addr, flags)
    48  		return ioComplete(flags, operr)
    49  	}
    50  	if err := c.c.Write(fn); err != nil {
    51  		return err
    52  	}
    53  	if operr != nil {
    54  		return os.NewSyscallError("sendmsg", operr)
    55  	}
    56  	m.N = n
    57  	m.NN = len(m.OOB)
    58  	return nil
    59  }