Listing 3. Real-Time Code--Handler for the Control FIFO

int my_handler(unsigned int fifo)
{
    struct my_msg_struct msg;
    int err;
    int handler_fd, rt_fd;

    handler_fd = open("/dev/rtf0", O_NONBLOCK);
    while ((err = read(handler_fd, &msg, sizeof(msg)))
    == sizeof(msg)) {
            char dest[10];
            sprintf(dest,"/dev/rtf%d",msg.task+1);
            rt_fd = open(dest, O_NONBLOCK);
            write(rt_fd, &msg, sizeof(msg));
            close(rt_fd);
    }
    close(handler_fd);
    if (err < 0)
            rtl_printf("Error getting data in handler,
            %d\n",err);
    return 0;
}