Asynchronous I/O Linux

2019-04-15 12:47发布

Need an async I/O Processing

Plan to use async I/O through aio* calls on Linux

The situation:

I have opened socket with AF_INET and SOCK_STREAM flags (TCP) Have limit high watermark for send buffers Want to write to that socket asynchronously, and when send buffer overflows, want to disconnect an socket

So, I have questions:

  1. When I made async call to aio_write on TCP socket, when I/O completion will arrives - when buffer written out into socket buffer or delivery is confirmed? How I can manage this behavior?

  2. How's best to handle this with lio_listio techniques

Regards, Andrew

1条回答
唯我独甜
2楼-- · 2019-04-15 13:19

You want to avoid AIO on Linux for anything real, at least for now, From aio(7):

The current Linux POSIX AIO implementation is provided in userspace by glibc. This has a number of limitations, most notably that maintaining multiple threads to perform I/O operations is expensive and scales poorly. Work has been in progress for some time on a kernel state-machine-based implementation of asynchronous I/O (see io_submit(2), io_setup(2), io_cancel(2), io_destroy(2), io_getevents(2)), but this implementation hasn't yet matured to the point where the POSIX AIO implementation can be completely reimplemented using the kernel system calls.

Instead, look into non-blocking IO with select(2)/poll(2)/epoll(7).

查看更多
登录 后发表回答