func writev(fd int, packet [][]byte) (n int, err error) { iovecs := make([]syscall.Iovec, 0, len(packet)) for _, v := range packet { if len(v) == 0 { continue } vec := syscall.Iovec{ Base: &v[0], } vec.SetLen(len(v)) iovecs = append(iovecs, vec) } n, errno := sys_writev(fd, &iovecs[0], len(iovecs)) if errno != 0 { err = os.NewSyscallError("writev", syscall.Errno(errno)) } return n, err }
func writev(fd int, packet [][]byte) (n int, err error) { iovecs := make([]syscall.Iovec, 0, len(packet)) for _, v := range packet { if len(v) == 0 { continue } vec := syscall.Iovec{ Base: &v[0], } vec.SetLen(len(v)) iovecs = append(iovecs, vec) } sysErr := handleEINTR(func() error { var err error n, err = sys_writev(fd, &iovecs[0], len(iovecs)) return err }) if sysErr != nil { err = os.NewSyscallError("writev", sysErr) } return n, err }
func sendMMsg(addr *net.UDPAddr, i int) { i = i / chunk_sz log.Printf("Start `sendMMsg` test with %d iteration\n", i) laddr := UDPAddrToSockaddr(&net.UDPAddr{Port: local_port, IP: net.IPv4zero}) raddr := UDPAddrToSockaddr(addr) fd := connectUDP(laddr, raddr) msgcnt := chunk_sz var msgArr [chunk_sz]MMsghdr for j := 0; j < msgcnt; j++ { p := make([]byte, payload_sz) for k := 0; k < payload_sz; k++ { p[k] = byte(k) } var iov syscall.Iovec iov.Base = (*byte)(unsafe.Pointer(&p[0])) iov.SetLen(len(p)) var msg syscall.Msghdr msg.Iov = &iov msg.Iovlen = 1 msgArr[j] = MMsghdr{msg, 0} } for ; i > 0; i-- { //_, _, e1 := syscall.Syscall6(C.SYS_sendmmsg, uintptr(fd), uintptr(unsafe.Pointer(&msgArr[0])), uintptr(msgcnt), uintptr(syscall.MSG_DONTWAIT), 0, 0) _, _, e1 := syscall.Syscall6(C.SYS_sendmmsg, uintptr(fd), uintptr(unsafe.Pointer(&msgArr[0])), uintptr(msgcnt), 0, 0, 0) if e1 != 0 { panic("error on sendmmsg") } } }