This will avoid your reader hanging indefinitely, if for what ever reason you don't receive expected transmissions in full.
Haven't tested it here but the usage should be something like:
Update: Corrected $TimeOut from ms to seconds.#!/usr/bin/perl use common::sense; use IO::Socket; use IO::Select; # establish connection my $socket = IO::Socket::UNIX->new( Peer => '/path/to/socket.file.sock', ); my $sel = IO::Select->new(); $sel->add($socket); # issue command and read answer my $some_command = 'foo'; print $socket "$some_command\n"; my $html = "<html>". sockread($sel,$socket). "</html>"; sub sockread { my $sel = shift; my $socket = shift; my $content; my $TimeOut = 0.5; #sec to wait while ($sel->can_read($TimeOut) && (my $line=<$socket>)){ $content .= $line; last if $line =~ /\[ End of /i; # vlc's rc is a bit in +consistent, some end like this last if $line =~ / returned 0 /i; # others like this } return $content; }
In reply to Re: Chunked unix socket file reading - how?
by snoopy
in thread Chunked unix socket file reading - how?
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |