(bufs [][]byte, sizes []int, offset int)
| 449 | } |
| 450 | |
| 451 | func (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 | |
| 478 | func (tun *NativeTun) Events() <-chan Event { |
| 479 | return tun.events |
nothing calls this directly
no test coverage detected