mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2025-04-29 22:55:06 +03:00
Contain vectorisation changes to the TUN package
This commit is contained in:
parent
c38544014c
commit
115d8a3b9d
3 changed files with 38 additions and 67 deletions
|
@ -31,23 +31,38 @@ func (tun *TunAdapter) read() {
|
|||
}
|
||||
}
|
||||
|
||||
func (tun *TunAdapter) write() {
|
||||
vs := tun.idealBatchSize()
|
||||
bufs := make([][]byte, vs)
|
||||
sizes := make([]int, vs)
|
||||
for i := range bufs {
|
||||
bufs[i] = make([]byte, TUN_OFFSET_BYTES+65535)
|
||||
}
|
||||
func (tun *TunAdapter) queue() {
|
||||
for {
|
||||
n, err := tun.rwc.ReadMany(bufs, sizes, TUN_OFFSET_BYTES)
|
||||
p := bufPool.Get().([]byte)[:bufPoolSize]
|
||||
n, err := tun.rwc.Read(p)
|
||||
if err != nil {
|
||||
tun.log.Errorln("Exiting TUN writer due to core read error:", err)
|
||||
return
|
||||
}
|
||||
tun.ch <- p[:n]
|
||||
}
|
||||
}
|
||||
|
||||
func (tun *TunAdapter) write() {
|
||||
vs := cap(tun.ch)
|
||||
bufs := make([][]byte, vs)
|
||||
for i := range bufs {
|
||||
bufs[i] = make([]byte, TUN_OFFSET_BYTES+65535)
|
||||
}
|
||||
for {
|
||||
n := len(tun.ch)
|
||||
if n == 0 {
|
||||
n = 1 // Nothing queued up yet, wait for it instead
|
||||
}
|
||||
for i := 0; i < n; i++ {
|
||||
msg := <-tun.ch
|
||||
bufs[i] = append(bufs[i][:TUN_OFFSET_BYTES], msg...)
|
||||
bufPool.Put(msg) // nolint:staticcheck
|
||||
}
|
||||
if !tun.isEnabled {
|
||||
continue // Nothing to do, the tun isn't enabled
|
||||
}
|
||||
if _, err = tun.iface.Write(bufs[:n], TUN_OFFSET_BYTES); err != nil {
|
||||
if _, err := tun.iface.Write(bufs[:n], TUN_OFFSET_BYTES); err != nil {
|
||||
tun.Act(nil, func() {
|
||||
if !tun.isOpen {
|
||||
tun.log.Errorln("TUN iface write error:", err)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue