in reply to Chunked unix socket file reading - how?
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; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Chunked unix socket file reading - how?
by Anonymous Monk on Nov 18, 2009 at 21:01 UTC | |
by snoopy (Curate) on Nov 18, 2009 at 21:59 UTC | |
|
Re^2: Chunked unix socket file reading - how?
by Anonymous Monk on Nov 18, 2009 at 19:56 UTC | |
|
Re^2: Chunked unix socket file reading - how?
by Anonymous Monk on Nov 18, 2009 at 20:26 UTC | |
|
Re^2: Chunked unix socket file reading - how?
by Anonymous Monk on Nov 18, 2009 at 20:45 UTC |