本文整理汇总了Golang中syscall.Overlapped.Offset方法的典型用法代码示例。如果您正苦于以下问题:Golang Overlapped.Offset方法的具体用法?Golang Overlapped.Offset怎么用?Golang Overlapped.Offset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类syscall.Overlapped
的用法示例。
在下文中一共展示了Overlapped.Offset方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Read
func (t *tun) Read(ch chan []byte) (err error) {
overlappedRx := syscall.Overlapped{}
var hevent windows.Handle
hevent, err = windows.CreateEvent(nil, 0, 0, nil)
if err != nil {
return
}
overlappedRx.HEvent = syscall.Handle(hevent)
buf := make([]byte, t.mtu)
var l uint32
for {
if err := syscall.ReadFile(t.fd, buf, &l, &overlappedRx); err != nil {
}
if _, err := syscall.WaitForSingleObject(overlappedRx.HEvent, syscall.INFINITE); err != nil {
fmt.Println(err)
}
overlappedRx.Offset += l
totalLen := 0
switch buf[0] & 0xf0 {
case 0x40:
totalLen = 256*int(buf[2]) + int(buf[3])
case 0x60:
continue
totalLen = 256*int(buf[4]) + int(buf[5]) + IPv6_HEADER_LENGTH
}
fmt.Println("read data", buf[:totalLen])
send := make([]byte, totalLen)
copy(send, buf)
ch <- send
}
}
示例2: Write
func (t *Interface) Write(ch chan []byte) (err error) {
tx := syscall.Overlapped{}
var hevent windows.Handle
hevent, err = windows.CreateEvent(nil, 0, 0, nil)
if err != nil {
return
}
tx.HEvent = syscall.Handle(hevent)
for {
select {
case data := <-ch:
var l uint32
syscall.WriteFile(t.file, data, &l, &tx)
syscall.WaitForSingleObject(tx.HEvent, syscall.INFINITE)
tx.Offset += uint32(len(data))
}
}
}
示例3: Read
func (t *Interface) Read(ch chan []byte) (err error) {
rx := syscall.Overlapped{}
var hevent windows.Handle
hevent, err = windows.CreateEvent(nil, 0, 0, nil)
if err != nil {
return
}
rx.HEvent = syscall.Handle(hevent)
buf := make([]byte, 1500)
var l uint32
for {
if err := syscall.ReadFile(t.file, buf, &l, &rx); err != nil {
}
if _, err := syscall.WaitForSingleObject(rx.HEvent, syscall.INFINITE); err != nil {
Log(Error, "Failed to read from TUN/TAP: %v", err)
}
rx.Offset += l
ch <- buf
}
}