new tun interface

This commit is contained in:
JackDoan
2026-04-17 10:25:05 -05:00
parent c08ed7d626
commit 7bb5cd477e
4 changed files with 36 additions and 4 deletions

View File

@@ -48,11 +48,15 @@ func (c *pollQueueSet) Add(fd int) error {
func (c *pollQueueSet) wakeForShutdown() error {
var buf [8]byte
binary.NativeEndian.PutUint64(buf[:], 1)
_, err := unix.Write(int(c.shutdownFd), buf[:])
_, err := unix.Write(c.shutdownFd, buf[:])
return err
}
func (c *pollQueueSet) Close() error {
if c.shutdownFd < 0 {
return nil
}
errs := []error{}
if err := c.wakeForShutdown(); err != nil {
@@ -65,5 +69,12 @@ func (c *pollQueueSet) Close() error {
}
}
// All Polls reference shutdownFd in their pollfd arrays, so close it
// only after every Poll.Close has returned.
if err := unix.Close(c.shutdownFd); err != nil {
errs = append(errs, err)
}
c.shutdownFd = -1
return errors.Join(errs...)
}