Mailing List archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Using 'select()' with the Siemens card driver?!



Does anybody know how to patch the Siemens card driver (version 0.039)
so that it works with the 'select()' function for both reading and writing?

I have attached a small test program to demonstrate what I want to do
(only the 'read()' case shown here).
The select call should return only if there is actual data to be
transferred from /dev/video (or after the given timeout). Once the
program has been signaled that there is data available, the 'read()'
call should read only that amount of data that is immediately available,
and then return (therefore the O_NONBLOCK in the 'open()' call).
The idea is to completely empty the driver's buffer and then have 
enough time to write away the data and respond to user input.

In the current driver version 'select()' doesn't work at all, and 'read()'
always waits until the buffer is completely filled (ignoring the O_NONBLOCK
flag).

Klaus Schmidinger
-- 
_______________________________________________________________

Klaus Schmidinger                       Phone: +49-8635-6989-10
CadSoft Computer GmbH                   Fax:   +49-8635-6989-40
Hofmark 2                               Email:   kls@cadsoft.de
D-84568 Pleiskirchen, Germany           URL:     www.cadsoft.de
_______________________________________________________________
    [ Part 2: "Attached Text" ]

#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <sys/time.h>
#include <unistd.h>

#define VIDEODEV "/dev/video"
#define BUFFERSIZE  1000000

int main(void)
{
  int v = open(VIDEODEV, O_RDWR | O_NONBLOCK);
  if (v >= 0) {
     for (;;) {
         fd_set set;
         FD_ZERO(&set);
         FD_SET(v, &set);
         struct timeval timeout;
         timeout.tv_sec = 1;
         timeout.tv_usec = 0;
         if (select(FD_SETSIZE, &set, NULL, NULL, &timeout) > 0) {
            if (FD_ISSET(v, &set)) {
               char buffer[BUFFERSIZE];
               int n = read(v, buffer, BUFFERSIZE);
               if (n > 0)
                  printf("read %d bytes\n", n);
               else if (n < 0)
                  fprintf(stderr, "ERROR: %s", strerror(errno));
               else
                  fprintf(stderr, "Ooops: 'select()' triggered, but no data read\n");
               }
            }
         else {
            printf(".");
            fflush(stdout);
            }
         }
     }
  else
     fprintf(stderr, "can't open %s\n", VIDEODEV);
}



Home | Main Index | Thread Index