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

Method Read

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

Source from the content-addressed store, hash-verified

449}
450
451func (tun *NativeTun) Read(bufs [][]byte, sizes []int, offset int) (int, error) {
452 tun.readOpMu.Lock()
453 defer tun.readOpMu.Unlock()
454 select {
455 case err := <-tun.errors:
456 return 0, err
457 default:
458 readInto := bufs[0][offset:]
459 if tun.vnetHdr {
460 readInto = tun.readBuff[:]
461 }
462 n, err := tun.tunFile.Read(readInto)
463 if errors.Is(err, syscall.EBADFD) {
464 err = os.ErrClosed
465 }
466 if err != nil {
467 return 0, err
468 }
469 if tun.vnetHdr {
470 return handleVirtioRead(readInto[:n], bufs, sizes, offset)
471 } else {
472 sizes[0] = n
473 return 1, nil
474 }
475 }
476}
477
478func (tun *NativeTun) Events() <-chan Event {
479 return tun.events

Callers

nothing calls this directly

Calls 2

handleVirtioReadFunction · 0.85
ReadMethod · 0.65

Tested by

no test coverage detected