$Bill Luebkert <> wrote:
> Brian Raven wrote:
> 
>> Well the example in 'perldoc IO::Select' seems to provide a basic
>> skeleton that can be fleshed out. However, as I am feeling generous
>> today for some reason, as well as suggesting that you RTFM, I have
>> fleshed it out a little. 
>> 
>> ----------------------------------------------------
>> use strict;
>> use warnings;
>> use IO::Select;
>> use IO::Socket;
>> my $lsn = new IO::Socket::INET(Listen => 1, LocalPort => 9876,
>> ReuseAddr => 1); my $sel = new IO::Select( $lsn ); while (my @ready
>>     = $sel->can_read) { foreach my $fh (@ready) {
>>      if ($fh == $lsn) {
>>          my $new = $lsn->accept;
>>          $sel->add($new);
>>          my $host = $new->peerhost;
>>          print "[Accepting connection from $host]\n";
>>      } else {
>>          my $line = <$fh>;
> 
> I would normally not be doing <> IO on a socket.  sysread is the
> better way to go IMO. 
> 
>>          $line =~ s/\s+$//;
>>          if ($line =~ /^quit/i) {
>>              my $host = $fh->peerhost;
>>              $sel->remove($fh);
>>              $fh->close;
>>              print "Connection from $host terminated\n";
>>          }
>>          else {
>>              print $fh->peerhost, " said '$line'\n";
>>              print $fh "You said: '$line'\n";
> 
> This echo print can lock you up.  can_write should be used to
> determine if write is prudent.  This is why a Qing system is probably
> the way to go for multi-client single server setup.  
> 
>>          }
>>      }
>>     }
>> }

Valid points, but as I said I was just fleshing out an existing example.
I was doing as little work as possible to generate a working, if
simplistic, demo. In general, for a single process, single threaded,
multi client server, then select, non-blocking i/o, sysread and syswrite
would be preferred for a more bomb proof solution. It also need a lot
more error checking, etc.

Also, it might be simpler, depending on requirements and design, to just
call syswrite instead of can_write. If using non-blocking i/o the
syswrite will either return EWOULDBLOCK or indicate a partial write if
tcp buffers are full. But yes you would need some mechanism such as a
queue to retain unsent data to try again later, whichever method you
chose.

HTH

-- 
Brian Raven 


=================================
Atos Euronext Market Solutions Disclaimer
=================================
The information contained in this e-mail is confidential and solely for the 
intended addressee(s). Unauthorised reproduction, disclosure, modification, 
and/or distribution of this email may be unlawful.
If you have received this email in error, please notify the sender immediately 
and delete it from your system. The views expressed in this message do not 
necessarily reflect those of Atos Euronext Market Solutions.

L'information contenue dans cet e-mail est confidentielle et uniquement 
destinee a la (aux) personnes a laquelle (auxquelle(s)) elle est adressee. 
Toute copie, publication ou diffusion de cet email est interdite. Si cet e-mail 
vous parvient par erreur, nous vous prions de bien vouloir prevenir 
l'expediteur immediatement et d'effacer le e-mail et annexes jointes de votre 
systeme. Le contenu de ce message electronique ne represente pas necessairement 
la position ou le point de vue d'Atos Euronext Market Solutions.

_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to