4

I know that the POSIX write function can return successfully even though it didn't write the whole buffer (if interrupted by a signal). You have to check for short writes and resume them.

But does aio_write have the same issue? I don't think it does, but it's not mentioned in the documentation, and I can't find anything that states that it doesn't happen.

cjm
  • 61,471
  • 9
  • 126
  • 175
  • [This other answer](http://stackoverflow.com/a/3697738/478288) says it does. – chrisaycock Mar 04 '13 at 16:55
  • @chrisaycock, true, but it also says he's never actually used aio_*, so he could be mistaken. – cjm Mar 04 '13 at 17:03
  • The caller does not need to call `aio_write()` more then once to pass the whole buffer to `aoi_write()`. This however is not a guarantee that the whole buffer passed in will be written. A final call to `aio_error()` gives the result of the **whole** asyncronous I/O operation. – alk Mar 04 '13 at 17:29

2 Answers2

1

The list of error codes on this page doesn't include EINTR, which is the value in errno that means "please call again to do some more work". So, no you shouldn't need to call aio_write again for the same piece of data to be written.

This doesn't mean that you can rely on every write being completed. You still could, for example, get an partial write because the disk is full or some such. But you don't need to check for EINTR and "try again".

Mats Petersson
  • 126,704
  • 14
  • 140
  • 227
  • Was "this page" supposed to be a link? – cjm Mar 04 '13 at 16:59
  • 1
    Also, `write` only returns `EINTR` if the signal interrupts it before any data is written. Otherwise, it returns success, but returns the number of bytes written as less than the number requested. – cjm Mar 04 '13 at 17:01
  • Fixed the link [my browser decided to restart, so I got a bit "lost" in what I was doing - should probably try another browser, but FF is usually pretty good]. – Mats Petersson Mar 04 '13 at 17:05
  • @MatsPetersson: Please don't link to die pages. That is a bloated source of outdated, unofficial information, also full of ads. It just so happens it shows up first in google results for many people due to SEO (in which SO generally helps to boost its search ratings). –  Mar 04 '13 at 18:41
1

Short answer

Excluding any case of error: Practical yes, theoratical not necessarily.

Long answer

From my experience the caller does not need to call aio_write() more then once to write the whole buffer using aoi_write().

This however is not a guarantee that the whole buffer passed in really will be written. A final call to aio_error() gives the result of the whole asyncronous I/O operation, which could indicate an error.

Anyhow the documentation does not explicitly excludes the case that the final call to aio_return() returns a value less then the amount of bytes to write out specified in the original call to aio_write(), what indeed needs to be interpreted as that not the whole buffer would have been sent, in which case it would be necessary to call aio_write() again passing in what whould have been indicated as having been left over to write by the previous call.

alk
  • 69,737
  • 10
  • 105
  • 255