github.com/shogo82148/std@v1.22.1-0.20240327122250-4e474527810c/internal/poll/fd_plan9.go (about) 1 // Copyright 2009 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package poll 6 7 import ( 8 "github.com/shogo82148/std/sync" 9 "github.com/shogo82148/std/time" 10 ) 11 12 type FD struct { 13 // Lock sysfd and serialize access to Read and Write methods. 14 fdmu fdMutex 15 16 Destroy func() 17 18 // deadlines 19 rmu sync.Mutex 20 wmu sync.Mutex 21 raio *asyncIO 22 waio *asyncIO 23 rtimer *time.Timer 24 wtimer *time.Timer 25 rtimedout bool 26 wtimedout bool 27 28 // Whether this is a normal file. 29 // On Plan 9 we do not use this package for ordinary files, 30 // so this is always false, but the field is present because 31 // shared code in fd_mutex.go checks it. 32 isFile bool 33 } 34 35 // Close handles the locking for closing an FD. The real operation 36 // is in the net package. 37 func (fd *FD) Close() error 38 39 // Read implements io.Reader. 40 func (fd *FD) Read(fn func([]byte) (int, error), b []byte) (int, error) 41 42 // Write implements io.Writer. 43 func (fd *FD) Write(fn func([]byte) (int, error), b []byte) (int, error) 44 45 // SetDeadline sets the read and write deadlines associated with fd. 46 func (fd *FD) SetDeadline(t time.Time) error 47 48 // SetReadDeadline sets the read deadline associated with fd. 49 func (fd *FD) SetReadDeadline(t time.Time) error 50 51 // SetWriteDeadline sets the write deadline associated with fd. 52 func (fd *FD) SetWriteDeadline(t time.Time) error 53 54 // ReadLock wraps FD.readLock. 55 func (fd *FD) ReadLock() error 56 57 // ReadUnlock wraps FD.readUnlock. 58 func (fd *FD) ReadUnlock() 59 60 // IsPollDescriptor reports whether fd is the descriptor being used by the poller. 61 // This is only used for testing. 62 func IsPollDescriptor(fd uintptr) bool 63 64 // RawControl invokes the user-defined function f for a non-IO 65 // operation. 66 func (fd *FD) RawControl(f func(uintptr)) error 67 68 // RawRead invokes the user-defined function f for a read operation. 69 func (fd *FD) RawRead(f func(uintptr) bool) error 70 71 // RawWrite invokes the user-defined function f for a write operation. 72 func (fd *FD) RawWrite(f func(uintptr) bool) error 73 74 func DupCloseOnExec(fd int) (int, string, error)