Note that there are some explanatory texts on larger screens.

plurals
  1. POIs it ever safe to combine select(2) and buffered IO for file handles?
    primarykey
    data
    text
    <p>I am using IO::Select to keep track of a variable number of file handles for reading. Documentation I've come across strongly suggests not to combine the select statement with &lt;> (readline) for reading from the file handles. </p> <p>My situation:</p> <p>I will only ever use each file handle once, i.e. when the select offers me the file handle, it will be completely used and then removed from the select. I will be receiving a hash and a variable number of files. I do not mind if this blocks for a time.</p> <p>For more context, I am a client sending information to be processed by my servers. Each file handle is a different server I'm talking to. Once the server is finished, a hash result will be sent back to me from each one. Inside that hash is a number indicating the number of files to follow.</p> <p>I wish to use readline in order to integrate with existing project code for transferring Perl objects and files.</p> <p>Sample code:</p> <pre><code>my $read_set = IO::Select()-&gt;new; my $count = @agents_to_run; #array comes as an argument for $agent ( @agents_to_run ) { ( $sock, my $peerhost, my $peerport ) = server($config_settings{ $agent }-&gt; { 'Host' },$config_settings{ $agent }-&gt;{ 'Port' }; $read_set-&gt;add( $sock ); } while ( $count &gt; 0) { my @rh_set = IO::Select-&gt;can_read(); for my $rh ( @{ $rh_set } ) { my %results = &lt;$rh&gt;; my $num_files = $results{'numFiles'}; my @files = (); for (my i; i &lt; $num_files; i++) { $files[i]=&lt;$rh&gt;; } #process results, close fh, decrement count, etc } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload