Does the libevent
deal with buffered file I/O? I know it handles sockets pretty good, but does it concern also normal files or it's "only" an epoll/...
wrapper?

- 23,584
- 43
- 124
- 195
3 Answers
Using libevent (or any of the underlying readiness notification mechanisms such as e.g. epoll
or kqueue
) with normal file descriptors does not normally make sense. Exceptions are files on NFS or using kernel AIO with an eventfd
.
File descriptors on local disks are always ready, there is always sufficient buffer space, and operations always complete "immediately". The write operation merely copies data to the buffer cache, and the actual write to the disk happens ... whenever it happens. (note that this link is Linux-specific, but apart from maybe some little implementation details it works the same on other systems)

- 67,688
- 20
- 135
- 185
libevent is not an epoll wrapper. It selects the highest performance method available on each platform.
Sockets are also file descriptors so you can should be able to use libevent for file io.
You will need to disable epoll usage of libevent though. If I remember right Epoll does not support unix files.
struct event_config *cfg = event_config_new();
event_config_avoid_method(cfg, "epoll");

- 3,488
- 2
- 37
- 56
libevent sits at a lower level than buffered file I/O (what you get with stdio.h
), using file descriptors directly. You are correct thinking that it is 'just' an epoll/select/kevent/etc wrapper. Its purpose is to listen for events on descriptors, which is the lowest level of file I/O. However, you can use it in conjunction with the stdio.h
file I/O library facilities, as that also eventually uses the file descriptors. You can use fileno(3)
to retrieve the file descriptor from the FILE *
you want to wait on.

- 3,608
- 1
- 21
- 28