[rrd-users] New rrdp read function

Jason jason_jks at yahoo.com
Thu May 24 01:17:43 CEST 2007


Hi all,

I still have not solved my RRDp::read problem, so I've written my own rrdp_read function based off of the RRDp::read() code in RRDp 12019.

I basically simplified the read function, and changed a few of the regular expressions and it seems to work for me.    However, I removed the vec() and select() lines, and things are still functioning properly.  Can someone explain what those are actually doing and if they're necessary?

I'm doing my own time calculations with Time::HiRes, so I removed the
^OK regexp almost completely, the only problem with my version of rrdtool, is that for some reason the buffer was registering "\nOK" instead of "OK" (new line before OK), so it never got into the $minibuf loop, it just sat in the while(1) infinitely.

Here is my read function.  It seems to work well.  Can anyone see any holes in it?

The return function returns two vars: success/failure and the address of error msg.

Thanks,
Jason Schoonover

---------------------------------------

sub rrdtool_read {
        my $sys_buffer;
        my $mini_buffer;
        my $buffer;

        while (1) {
                sysread (READ, $sys_buffer, 4096);
                $mini_buffer .= $sys_buffer;

                while ($mini_buffer =~ s|^\s*(.+?)\n||s) {
                        my $line = $1;
                        
                        ## this means there was an error
                        if ($line =~ /^ERROR/) {
                                return (1, \$line);
                        
                        ## this means either it was finished and everything is good
                        ## or the syntax or command was wrong
                        ## either way, we need to exit after this and say it was a success
                        } elsif ($line =~ /^OK/) {
                                return (0, \$buffer);
                        
                        } else {
                                $buffer .= $line . "\n";
                        }
                }
        }
}





More information about the rrd-users mailing list