Fix too many segments read error

This commit is contained in:
Neil Alexander 2024-07-20 12:48:42 +01:00
parent 115d8a3b9d
commit 36e68317d4
No known key found for this signature in database
GPG key ID: A02A2019A2BB0944
2 changed files with 2 additions and 10 deletions

View file

@ -1,17 +1,9 @@
package tun
const TUN_OFFSET_BYTES = 80 // sizeof(virtio_net_hdr)
const TUN_MAX_VECTOR = 16
func (tun *TunAdapter) idealBatchSize() int {
if b := tun.iface.BatchSize(); b <= TUN_MAX_VECTOR {
return b
}
return TUN_MAX_VECTOR
}
func (tun *TunAdapter) read() {
vs := tun.idealBatchSize()
vs := tun.iface.BatchSize()
bufs := make([][]byte, vs)
sizes := make([]int, vs)
for i := range bufs {

View file

@ -162,7 +162,7 @@ func (tun *TunAdapter) _start() error {
tun.rwc.SetMTU(tun.MTU())
tun.isOpen = true
tun.isEnabled = true
tun.ch = make(chan []byte, tun.idealBatchSize())
tun.ch = make(chan []byte, tun.iface.BatchSize())
go tun.queue()
go tun.read()
go tun.write()