[Gllug] Delayed data feed

Robert McKay robert at mckay.com
Wed Jan 12 17:32:55 UTC 2011

On Wed, Jan 12, 2011 at 4:33 PM, - Tethys <tethys at gmail.com> wrote:

> Does anyone know of a simple delay utility that consumes data from
> stdin and outputs it on stdout a fixed time later? What I want to be
> able to do is:
>        mkdata | delay 30 | send_data_to_customer
> That will send the (time sensitive) output of mkdata to the customer
> with a 30 second delay. The amount of data I'm talking about isn't so
> large that I need to worry about memory usage, and buffering it in RAM
> will work just fine. I can write it myself, but I'd rather not
> reinvent the wheel if someone's already done it.

You could pipe it through a series of netcats such that the latency along
the path is 30 seconds. 50 roundtrips to japan should do it. ;-)

It's sortof an interesting problem as to do it properly you really need to
timestamp every read().

You could perhaps create artificial latency using netem perhaps making the
nc idea almost practical.

Here's some crappy perl I made that may work. I think.

use IO::Select;

my $delay = 30;
my @stuff = ();

my $s = IO::Select->new();

 if ($s->can_read(1) )
   sysread(STDIN, $chunk, 1024);
   push @stuff, { time=>time(), chunk=>$chunk };

 if (my $test = shift(@stuff))

   if ($test->{time} <= (time()-$delay) )
     print $test->{chunk};
   } else {  unshift(@stuff, $test); }


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.lug.org.uk/pipermail/gllug/attachments/20110112/5f15b235/attachment.html>
-------------- next part --------------
Gllug mailing list  -  Gllug at gllug.org.uk

More information about the GLLUG mailing list