本文整理汇总了Golang中syscall.Iovec.SetLen方法的典型用法代码示例。如果您正苦于以下问题:Golang Iovec.SetLen方法的具体用法?Golang Iovec.SetLen怎么用?Golang Iovec.SetLen使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类syscall.Iovec
的用法示例。
在下文中一共展示了Iovec.SetLen方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: writev
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
}
示例2: writev
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
}
示例3: sendMMsg
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")
}
}
}