Home

EVFILTWRITE

EVFILT_WRITE is a filter in the BSD kqueue I/O event notification system. It reports when a file descriptor is ready for writing, meaning a non-blocking write to the descriptor would not block. This filter is commonly used with sockets, pipes, and other streaming descriptors to implement asynchronous or event-driven I/O.

Usage typically involves creating a kqueue object and registering the target descriptor with the EVFILT_WRITE filter

EVFILT_WRITE is frequently used in conjunction with EVFILT_READ to implement asynchronous I/O loops, enabling the program

Notes and considerations include the need to handle partial writes, non-blocking error conditions, and re-arming the

using
EV_ADD
and,
often,
EV_ENABLE.
When
the
system
indicates
a
write
event
for
that
descriptor,
the
application
performs
write
operations.
After
writing,
the
application
may
continue
to
receive
EVFILT_WRITE
events
as
long
as
the
descriptor
remains
writable,
or
until
it
no
longer
is
(for
example,
if
the
peer
back-pressures
the
connection
or
the
send
buffer
fills).
The
data
field
in
the
returned
kevent
may
convey
the
amount
of
space
available
in
the
send
buffer,
and
EV_ERROR
may
be
returned
to
indicate
an
error
condition
to
check
via
errno.
to
react
to
both
readiness
for
reading
and
readiness
for
writing
on
multiple
descriptors.
It
is
a
BSD-specific
mechanism
and
is
not
part
of
the
Linux
epoll
family;
other
platforms
provide
different
interfaces
for
similar
functionality.
event
after
each
operation
when
appropriate.
Proper
error
handling
and
cleanup
are
essential
to
avoid
busy
loops
or
resource
leaks.