5

I'm working on a TFTP implementation that is transitioning away from a convoluted multi-threaded implementation to a single-thread/single-process implementation which uses a state machine to track the state of the sessions connected. TFTP is simple enough, and the number of concurrent sessions are small enough that the there really is no impact to the software other than massive code-size & complexity savings.

Of course, I can't just block on a single session when others are connected. To remedy this, my first thought was POSIX AIO, though after some research I read that it's

  • Poorly Documented, and not complete
  • Only works on Disk I/O and does not support sockets, or works on sockets but only for read/writes - Not for listening.

An example is contained in this link (http://davmac.org/davpage/linux/async-io.html), though I found others as well. Some additional perspective was given in a prior stackoverflow post (What is the status of POSIX asynchronous I/O (AIO)?) from '08.

For a C developer, is AIO still as broken as people claim? Do people really not use AIO, and stick primarily to poll/select or finite size thread pools?

Community
  • 1
  • 1
Bob
  • 2,002
  • 3
  • 16
  • 18
  • This seems to just be a duplicate of my earlier question. Is there anything you want to know other than "is that still valid"? – Glyph Sep 20 '12 at 18:44

5 Answers5

1

Poorly documented is certainly the case.

Most people do stick with poll() / select(), simply because these are well-understood, well-tested, well-documented and well-supported. If I were you I would use select() unless you have a compelling reason not to.

caf
  • 233,326
  • 40
  • 323
  • 462
0

You might consider Boost.Asio for a cross-platform asynchronous socket library. It has excellent examples and is documented extensively.

Sam Miller
  • 23,808
  • 4
  • 67
  • 87
  • Thanks, but unfortunately, the software itself is written in C and probably will not change (it will be certified, Level D avionics software - My company coding standards require use of C). I guess I used the "C/C++" reference a bit carelessly. – Bob Jul 06 '10 at 17:36
  • @Robert that is too bad. You might want to remove the c++ flag in your question then. – Sam Miller Jul 06 '10 at 19:38
0

I can't answer your question about POSIX AIO, but I've used libev for events. Small, fast, simple. Makes a good wrapper for IO in place of poll/select.

Ioan
  • 2,382
  • 18
  • 32
0

The issues with aio depend on the platform, so a big part of your decision is what platform you are targeting. Quality varies widely and in some cases it is implemented in terms of poll/select type calls.

People do tend to use poll/select or similar interfaces like kevent/kqueue or epoll for this kind of thing on Unix platforms.

There are problems with the aio interface, and additions like aio_waitcomplete() and the integration of aio and kqueues makes a difference.

Lots of threads for dealing with lots of I/O is not a good approach.

janm
  • 17,976
  • 1
  • 43
  • 61
0

for disk, why do you have to have AIO instead of just buffered read/write, unless you want to 1) use your own caching 2) control the impact on dirty pages or 3) use IO priorities?

Because if your goal is only code refactoring, then you probably go through cache in the current version. Changing from buffered IO to direct IO is a huge change.

For example, on ext3/SSD/noop with 1,5G of RAM, just 3 threads doing streamed writes of 300Mb starve small writes and reads. Switching the offenders to direct IO fixes that, but the writes now take forever.

n-alexander
  • 14,663
  • 12
  • 42
  • 43