MCPcopy Create free account
hub / github.com/encodeous/nylon / Write

Method Write

polyamide/tun/tun_linux.go:335–370  ·  view source on GitHub ↗
(bufs [][]byte, offset int)

Source from the content-addressed store, hash-verified

333}
334
335func (tun *NativeTun) Write(bufs [][]byte, offset int) (int, error) {
336 tun.writeOpMu.Lock()
337 defer func() {
338 tun.tcpGROTable.reset()
339 tun.udpGROTable.reset()
340 tun.writeOpMu.Unlock()
341 }()
342 var (
343 errs error
344 total int
345 )
346 tun.toWrite = tun.toWrite[:0]
347 if tun.vnetHdr {
348 err := handleGRO(bufs, offset, tun.tcpGROTable, tun.udpGROTable, tun.udpGSO, &tun.toWrite)
349 if err != nil {
350 return 0, err
351 }
352 offset -= virtioNetHdrLen
353 } else {
354 for i := range bufs {
355 tun.toWrite = append(tun.toWrite, i)
356 }
357 }
358 for _, bufsI := range tun.toWrite {
359 n, err := tun.tunFile.Write(bufs[bufsI][offset:])
360 if errors.Is(err, syscall.EBADFD) {
361 return total, os.ErrClosed
362 }
363 if err != nil {
364 errs = errors.Join(errs, err)
365 } else {
366 total += n
367 }
368 }
369 return total, errs
370}
371
372// handleVirtioRead splits in into bufs, leaving offset bytes at the front of
373// each buffer. It mutates sizes to reflect the size of each element of bufs,

Callers

nothing calls this directly

Calls 3

handleGROFunction · 0.85
WriteMethod · 0.65
resetMethod · 0.45

Tested by

no test coverage detected