Skip to content

Commit

Permalink
Fix too many segments read error
Browse files Browse the repository at this point in the history
  • Loading branch information
neilalexander committed Jul 20, 2024
1 parent 115d8a3 commit 36e6831
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 10 deletions.
10 changes: 1 addition & 9 deletions src/tun/iface.go
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/tun/tun.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 36e6831

Please sign in to comment.