Re: Problems with aio_read
Re: Problems with aio_read
- Subject: Re: Problems with aio_read
- From: Richard Schmitt <email@hidden>
- Date: Sat, 11 Oct 2008 13:51:46 -0700 (PDT)
I downloaded the darwin kernel source and saw a comment in kern_aio.c:
/* validate aiocb.aio_sigevent. at this point we only support sigev_notify
* equal to SIGEV_SIGNAL or SIGEV_NONE. this means sigev_value,
* sigev_notify_function, and sigev_notify_attributes are ignored.
*/
So, wow, a comment that answered my question. Too bad this isn't in the man pages for aio.
My workaround for 10.4 is to create my own completion queue and when I get a signal, I'll traverse the completion queue looking for aiocb's that completed. What I was hoping to do was get the signal with the aiocb as the sig value. It saves me from having to maintain the completion queue.
If there's a better way, I'd like to hear it.
I might decide to restrict the application to 10.5, but I was hoping to make it work on 10.4.
Thanks for your response.
Rich
----- Original Message ----
From: Terry Lambert <email@hidden>
To: Richard Schmitt <email@hidden>
Cc: "email@hidden" <email@hidden>
Sent: Saturday, October 11, 2008 12:19:25 PM
Subject: Re: Problems with aio_read
On Oct 11, 2008, at 5:50 AM, Richard Schmitt <email@hidden>
wrote:
> I'm trying to use aio_read in an application and am having problems
> with the completion notifications.
>
> When I use signals, I'll get a signal for the completion, but the
> siginfo structure does not have the si_value filled in.
>
> When I use notify functions, the aio_read call fails with invalid
> argument.
>
> Here's some sample code:
>
> my_action.sa_sigaction = my_handler ;
> my_action.sa_flags = SA_SIGINFO ;
> sigaction (SIGIO, &my_action, NULL) ;
>
> cb = malloc (sizeof (struct aiocb)) ;
> memset (cb, '\0', sizeof (struct aiocb)) ;
> cb->aio_fildes = open ("sigtest.c", O_NONBLOCK) ;
> cb->aio_buf = malloc (1001) ;
> cb->aio_nbytes = 1001 ;
> cb->aio_offset = 0 ;
>
> cb->aio_sigevent.sigev_value.sival_ptr = cb ;
> cb->aio_sigevent.sigev_signo = SIGIO ;
> cb->aio_sigevent.sigev_notify = SIGEV_SIGNAL ;
>
> ret = aio_read (cb) ;
>
> When the IO completes, I expect a SIGIO signal and the siginfo
> structure passed to my_handler will have the si_value set to the
> cb. The example handler is below:
>
> void my_handler (int sig, siginfo_t *siginfo, void* context)
> {
> struct aiocb *cb ;
>
> cb = siginfo->si_value.sival_ptr ;
>
> cb is always NULL.
>
> I'm running OSX 10.4.11
The aio implementation in 10.4 is not fully POSIX conformant. If your
code needs full POSIX conformance, it should be including <unistd.h>
and checking _POSIX_ASYNCHRONUS_IO has a value greater than or equal
to 200112L before using the interface.
There are a number of workaround that you could use if you wanted to
run on something as old as 10.4, but you would need to explain the
problem you are trying to solve for us to tell you which ones might be
appropriate.
-- Terry
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden