@@ -78,6 +78,21 @@ if sys.platform != "linux" and sys.platform != "win32":
7878 # BSD only
7979 @final
8080 class kevent :
81+ """kevent(ident, filter=KQ_FILTER_READ, flags=KQ_EV_ADD, fflags=0, data=0, udata=0)
82+
83+ This object is the equivalent of the struct kevent for the C API.
84+
85+ See the kqueue manpage for more detailed information about the meaning
86+ of the arguments.
87+
88+ One minor note: while you might hope that udata could store a
89+ reference to a python object, it cannot, because it is impossible to
90+ keep a proper reference count of the object once it's passed into the
91+ kernel. Therefore, I have restricted it to only storing an integer. I
92+ recommend ignoring it and simply using the 'ident' field to key off
93+ of. You could also set up a dictionary on the python side to store a
94+ udata->object mapping.
95+ """
8196 data : Any
8297 fflags : int
8398 filter : int
@@ -98,15 +113,48 @@ if sys.platform != "linux" and sys.platform != "win32":
98113 # BSD only
99114 @final
100115 class kqueue :
116+ """Kqueue syscall wrapper.
117+
118+ For example, to start watching a socket for input:
119+ >>> kq = kqueue()
120+ >>> sock = socket()
121+ >>> sock.connect((host, port))
122+ >>> kq.control([kevent(sock, KQ_FILTER_WRITE, KQ_EV_ADD)], 0)
123+
124+ To wait one second for it to become writeable:
125+ >>> kq.control(None, 1, 1000)
126+
127+ To stop listening:
128+ >>> kq.control([kevent(sock, KQ_FILTER_WRITE, KQ_EV_DELETE)], 0)
129+ """
101130 closed : bool
102131 def __init__ (self ) -> None : ...
103- def close (self ) -> None : ...
132+ def close (self ) -> None :
133+ """Close the kqueue control file descriptor.
134+
135+ Further operations on the kqueue object will raise an exception.
136+ """
104137 def control (
105138 self , changelist : Iterable [kevent ] | None , maxevents : int , timeout : float | None = None , /
106- ) -> list [kevent ]: ...
107- def fileno (self ) -> int : ...
139+ ) -> list [kevent ]:
140+ """Calls the kernel kevent function.
141+
142+ changelist
143+ Must be an iterable of kevent objects describing the changes to be made
144+ to the kernel's watch list or None.
145+ maxevents
146+ The maximum number of events that the kernel will return.
147+ timeout
148+ The maximum time to wait in seconds, or else None to wait forever.
149+ This accepts floats for smaller timeouts, too.
150+ """
151+ def fileno (self ) -> int :
152+ """Return the kqueue control file descriptor.
153+ """
108154 @classmethod
109- def fromfd (cls , fd : FileDescriptorLike , / ) -> kqueue : ...
155+ def fromfd (cls , fd : FileDescriptorLike , / ) -> kqueue :
156+ """Create a kqueue object from a given control fd.
157+ """
110158
111159 KQ_EV_ADD : Final [int ]
112160 KQ_EV_CLEAR : Final [int ]
0 commit comments