I'm trying to use the aio_ * functions for asynchronous IO I / O on Mac OS X, but I'm having problems getting some form of user data into a signal handler.
This is the code that sets up the operation:
class aio_context {
public:
aio_context(int fildes, boost::uint64_t offset,
const MyBufferClassPtr &buffer)
{
memset(&m_aiocb, 0, sizeof(struct aiocb));
m_aiocb.aio_fildes = fildes;
m_aiocb.aio_buf = buffer->data();
m_aiocb.aio_nbytes = buffer->size();
m_aiocb.aio_offset = offset;
m_aiocb.aio_sigevent.sigev_notify = SIGEV_SIGNAL;
m_aiocb.aio_sigevent.sigev_signo = SIGUSR1;
m_aiocb.aio_sigevent.sigev_value.sival_ptr = this;
}
struct aiocb* GetAiocbp()
{
return &m_aiocb;
}
private:
struct aiocb m_aiocb;
};
Then called from another place:
aio_context *ctx = new aio_context(file_descriptor, offset, data);
int ret = aio_write(ctx->GetAiocbp());
if (0 != ret) {
}
My signal processing setup is as follows:
sigemptyset(&m_CurrentSIGHandler.sa_mask);
m_CurrentSIGHandler.sa_sigaction = aio_completion_handler;
m_CurrentSIGHandler.sa_flags = SA_SIGINFO;
sigaction(SIGUSR1, &m_CurrentSIGHandler, &m_PreviousSIGHandler);
and the actual handler:
void aio_completion_handler(int signo, siginfo_t *info, void *context)
{
if (info->si_signo == SIGUSR1) {
aio_context *ctx = static_cast<aio_context *>(info->si_value.sival_ptr);
assert(ctx);
}
}
So the problem is that si_value.sival_ptr is always NULL in the signal handler, instead of the aio_context pointer that I set in the aiocb structure. I must have misunderstood how to do this, so can someone tell me what I'm doing wrong?
MacOSX 10.6, ( ) 10.5, .
, , , , AIO - ?
Update:
- http://lists.apple.com/archives/darwin-dev/2008/Oct/msg00054.html.
http://www.opensource.apple.com/source/xnu/xnu-1504.9.26/bsd/kern/kern_aio.c, , , sigev_value . , , aio_ * Mac OS X. , , . - , aio_ * ?