put in a prototype echo handler in Msg/ExtMsg
[spider.git] / perl / Msg.pm
index 3f52e39dfe8057d4fb202f364be81eb36567ceb3..615feb1987e4a102def727f208d093107f63d85b 100644 (file)
@@ -386,11 +386,29 @@ sub _rcv {                     # Complement to _send
        $bytes_read = sysread ($sock, $msg, 1024, 0);
        if (defined ($bytes_read)) {
                if ($bytes_read > 0) {
-                       $conn->{msg} .= $msg;
                        if (isdbg('raw')) {
                                my $call = $conn->{call} || 'none';
                                dbgdump('raw', "$call read $bytes_read: ", $msg);
                        }
+                       if ($conn->{echo}) {
+                               my @ch = split //, $msg;
+                               my $out;
+                               for (@ch) {
+                                       if (/[\cH\x7f]/) {
+                                               $out .= "\cH \cH";
+                                               $conn->{msg} =~ s/.$//;
+                                       } else {
+                                               $out .= $_;
+                                               $conn->{msg} .= $_;
+                                       }
+                               }
+                               if (defined $out) {
+                                       set_event_handler ($sock, write => sub{$conn->_send(0)});
+                                       push @{$conn->{outqueue}}, $out;
+                               }
+                       } else {
+                               $conn->{msg} .= $msg;
+                       }
                } 
        } else {
                if (_err_will_block($!)) {