<?xml version="1.0" encoding="windows-1252"?>
<node id="808005" title="Re: Chunked unix socket file reading - how?" created="2009-11-18 14:53:43" updated="2009-11-18 14:53:43">
<type id="11">
note</type>
<author id="414875">
snoopy</author>
<data>
<field name="doctext">
[mod://IO::Select] will let you do a timed-wait for input. 
&lt;p&gt;
This will avoid your reader hanging indefinitely, if for what ever reason you don't receive expected transmissions in full.
&lt;p&gt;
Haven't tested it here but the usage should be something like:
&lt;code&gt;
#!/usr/bin/perl
use common::sense;
use IO::Socket;
use IO::Select;

# establish connection
my $socket = IO::Socket::UNIX-&gt;new(
     Peer    =&gt; '/path/to/socket.file.sock',
    );

my $sel = IO::Select-&gt;new();
$sel-&gt;add($socket);

# issue command and read answer
my $some_command = 'foo';
print $socket "$some_command\n";
my $html = "&lt;html&gt;". sockread($sel,$socket). "&lt;/html&gt;";

sub sockread {
    my $sel = shift;
    my $socket = shift;
    my $content;
    my $TimeOut = 0.5; #sec to wait

    while ($sel-&gt;can_read($TimeOut) &amp;&amp; (my $line=&lt;$socket&gt;)){
        $content .= $line;
        last if $line =~ /\[ End of /i;         # vlc's rc is a bit inconsistent, some end like this
        last if $line =~ / returned 0 /i;       # others like this
    }
    return $content;
}
&lt;/code&gt;
&lt;b&gt;Update: &lt;/b&gt; Corrected &lt;code&gt;$TimeOut&lt;/code&gt; from ms to seconds.
</field>
<field name="root_node">
807990</field>
<field name="parent_node">
807990</field>
</data>
</node>
