Using select() to detect a block on a UIO device file
<p>I'm working on an embedded processor running Yocto. I have a modified <em>uio_pdrv_genirq.c</em> UIO driver.</p>

<p>I am writing a library to control the DMA. There is one function which writes to the device file and initiates the DMA. A second function is intended to wait for the DMA to complete by calling <em>select()</em>. Whilst DMA is in progress the device file blocks. On completion the DMA controller issues an interrupt which releases the block on the device file.</p>

<p>I have the system working as expected using <em>read()</em> but I want to switch to <em>select()</em> so that I can include a time out. However, when I use <em>select()</em>, it doesn't seem to be recognising the block and always returns immediately (before the DMA has completed). I have included a simple version of the code:</p>

<pre><code>int gannet_dma_interrupt_wait(dma_device_t *dma_device,
        dma_direction dma_transfer_direction) {

    fd_set rfds;
    struct timeval timeout;
    int select_res;

    /* Initialize the file descriptor set and add the device file */
    FD_ZERO(&amp;rfds);
    FD_SET(dma_device-&gt;fd, &amp;rfds);

    /* Set the timeout period. */
    timeout.tv_sec = 5;
    timeout.tv_usec = 0;

    /* The device file will block until the DMA transfer has completed. */
    select_res = select(FD_SETSIZE, &amp;rfds, NULL, NULL, &amp;timeout);

    /* Reset the channel */
    gannet_dma_reset(dma_device, dma_transfer_direction);

    if (select_res == -1) {
        /* Select has encountered an error */
        perror("ERROR &lt;Interrupt Select Failed&gt;\n");
        exit(0);
    }
    else if (select_res == 1) {
        /* The device file descriptor block released */
        return 0;
    }
    else {
        /* The device file descriptor block exceeded timeout */
        return EINTR;
    }
}
</code></pre>

<p>Is there anything obviously wrong with my code? Or can anyone suggest an alternative to select?</p>