about summary refs log tree commit
diff options
context:
space:
mode:
authorGraham Barr <gbarr@pobox.com>2006-10-22 17:39:50 +0000
committerGraham Barr <gbarr@pobox.com>2009-02-24 10:40:47 -0600
commita0cf376daae1ea8e56fc5d2572e346e0074d465b (patch)
tree90f47b575f0343a18e91fdd0bb4f77b8e741310a
parent59799cf5bd09045697a9dcbfc429ee96cefb2674 (diff)
downloadperl-libnet-a0cf376daae1ea8e56fc5d2572e346e0074d465b.tar.gz
Fix slow regexp in data when scalar passed has utf8 flag set
Catch select returning an error (patch from Ben Evans)
-rw-r--r--Net/Cmd.pm21
1 files changed, 12 insertions, 9 deletions
diff --git a/Net/Cmd.pm b/Net/Cmd.pm
index f7c7484..201349f 100644
--- a/Net/Cmd.pm
+++ b/Net/Cmd.pm
@@ -1,6 +1,6 @@
 # Net::Cmd.pm $Id: //depot/libnet/Net/Cmd.pm#34 $
 #
-# Copyright (c) 1995-1997 Graham Barr <gbarr@pobox.com>. All rights reserved.
+# Copyright (c) 1995-2006 Graham Barr <gbarr@pobox.com>. All rights reserved.
 # This program is free software; you can redistribute it and/or
 # modify it under the same terms as Perl itself.
 
@@ -21,7 +21,9 @@ BEGIN {
   }
 }
 
-$VERSION = "2.26_01";
+my $doUTF8 = eval { require utf8 };
+
+$VERSION = "2.27";
 @ISA     = qw(Exporter);
 @EXPORT  = qw(CMD_INFO CMD_OK CMD_MORE CMD_REJECT CMD_ERROR CMD_PENDING);
 
@@ -266,7 +268,9 @@ sub getline
   {
    my $timeout = $cmd->timeout || undef;
    my $rout;
-   if (select($rout=$rin, undef, undef, $timeout))
+
+   my $select_ret = select($rout=$rin, undef, undef, $timeout);
+   if ($select_ret > 0)
     {
      unless (sysread($cmd, $buf="", 1024))
       {
@@ -287,7 +291,8 @@ sub getline
     }
    else
     {
-     carp("$cmd: Timeout") if($cmd->debug);
+     my $msg = $select_ret ? "Error or Interrupted: $!" : "Timeout";
+     carp("$cmd: $msg") if($cmd->debug);
      return undef;
     }
   }
@@ -390,6 +395,8 @@ sub datasend
  my $arr = @_ == 1 && ref($_[0]) ? $_[0] : \@_;
  my $line = join("" ,@$arr);
 
+ utf8::encode($line) if $doUTF8;
+
  return 0 unless defined(fileno($cmd));
 
  my $last_ch = ${*$cmd}{'net_cmd_last_ch'};
@@ -767,12 +774,8 @@ Graham Barr <gbarr@pobox.com>
 
 =head1 COPYRIGHT
 
-Copyright (c) 1995-1997 Graham Barr. All rights reserved.
+Copyright (c) 1995-2006 Graham Barr. All rights reserved.
 This program is free software; you can redistribute it and/or modify
 it under the same terms as Perl itself.
 
-=for html <hr>
-
-I<$Id: //depot/libnet/Net/Cmd.pm#34 $>
-
 =cut