Skip navigation.
The QNX Community Portal

View topic - aio_read error

aio_read error

For discussion of realtime and/or embedded programming.

aio_read error

Postby priyanka » Mon Mar 15, 2010 8:53 am

void read_Handler(int);
struct aiocb asyncRead;
char readBuf[10];

int main (void)
int totalRead=0;
int fd;
struct sigevent readEvent;
struct termios termios_p;

//Use this section to initialize the signals that will be delivered.

//Use the following call to open the serial port.

fd = open ("/dev/ser1", O_RDWR, O_NONBLOCK);

//The following structure asyncWrite is filled and the event info filled in.
asyncRead.aio_fildes = fd;
asyncRead.aio_buf = &readBuf;
asyncRead.aio_nbytes = 10;
asyncRead.aio_sigevent = readEvent;
asyncRead.aio_sigevent.sigev_notify = SIGEV_SIGNAL;
asyncRead.aio_lio_opcode = LIO_NOWAIT;
//Here you specify the signal handlers.
signal(SIGUSR2, read_Handler);

sleep(10); //Intentional
return 0;

void read_Handler (int signo)
printf(" Read Handler Called \n");
printf("Read Data is as follow [%s] \n",readBuf);
printf("Read Data is as follow [%s] ",asyncRead.aio_buf);//readBuf);

I have written the above code for implementing aio_read().I have the following doubts;
1. Read handler is called even if I'm not writing any data to the port, I don't understand why?
2. Can VMIN and VTIME attributes of the termios structure be used with aio_read()?
3. I have a doubt regarding aio_nbytes feild of the aiocb structure. Does it mean the number of bytes to return in each read or the maximum no of bytes to read in each read whether or not enough data is available in the aio_buf.
Active Member
Posts: 11
Joined: Thu Jul 16, 2009 4:42 am

Return to Realtime and Embedded

Who is online

Users browsing this forum: No registered users and 1 guest