struct aiocb asyncRead;
int main (void)
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. memset(readBuf,0,10); 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.
aio_read(&asyncRead); sleep(10); //Intentional close(fd); 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;
- Read handler is called even if I’m not writing any data to the port, I don’t understand why?
- Can VMIN and VTIME attributes of the termios structure be used with aio_read()?
- 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.