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

Re: 20031013: data stops ingesting from SDI



David,

Most excellent!

Thanks for sending this in.

Regards,
Steve Emmerson

>Date: 14 Oct 2003 01:00:07 -0500
>From: David Larson <address@hidden>
>Organization: digitalcyclone
>To: Steve Emmerson <address@hidden>
>Subject: Re: 20031013: data stops ingesting from SDI
>
> For those watching this thread and having similar problems, I've gone a
> bit further and I have what seems to be a working solution to this
> problem.
> 
> The "cat" utility in SDI is just the vanilla UNIX cat.  It is started
> from INETD (configured with /etc/inetd.conf).  Therefore, it was simple
> to replace it.
> 
> I wrote an enhanced utility that is similar to cat but also reads and
> discards the nul-characters sent from LDM (stdin).  I have been running
> the following code for about 6 hours without any problems.
> 
> If anyone finds this useful, feel free to use it.  You'll need to
> compile it, place the resulting binary somewhere sensible, and change
> the "/bin/cat" in /etc/inetd.conf to point to it.
> 
> Of course, use at your own risk.  If you don't understand how it works
> or how to make it work, you probably shouldn't do anything with it.
> 
> Goodluck,
> Dave
> 
> ------------------------------
> 
> #include <stdio.h>
> #include <errno.h>
> #include <sys/fcntl.h>
> #include <poll.h>
>  
> int
> main(int argc, char ** argv)
> {
>     int fd;
>     char buf[16384];
>     int len;
>     struct pollfd fds[1];
>     char fname[1024];
>  
>     if (argc <= 1) {
>         fprintf(stderr, "Usage: %s filename\n", argv[0]);
>         exit(1);
>     }
>  
>     if ((fd = open(argv[1], O_RDONLY)) < 0) {
>         fprintf(stderr, "Failed to open '%s', %s\n",
>                 argv[1], strerror(errno));
>         exit(1);
>     }
>  
>     fds[0].fd = 0;  // standard input should be coming from a TCP socket
>     fds[0].events = POLLIN;
>  
>     while ((len = read(fd, buf, sizeof(buf))) > 0) { // read the fifo
>         int readReady;
>         int wrot;
>         char * p = buf;
>         while ((wrot = write(1, p, len)) < len) { // write to stdout
>             if (wrot < 0) {
>                 fprintf(stderr, "Failed to write, %s", strerror(errno));
>                 exit(1);
>             }
>             p += wrot;
>             len -= wrot;
>         }
>         // check for data to be read on stdin
>         if ((readReady = poll(fds, 1, 0)) == 1) {
>             if (fds[0].revents & (POLLHUP|POLLERR)) { // LDM hungup
>                 exit(1);
>             } else {
>                 // data is ready to be read from LDM, read & discard
>                 read(fds[0].fd, buf, sizeof(buf));
>             }
>         }
>     }
>     close(fd);
> }
>