perl - socat blocking on stdin -
i have bash script follow on aix host, myscript.sh:
mode="$1" if [ "$mode" == "start" ]; socat -t100 -lf $logf -d -d -d -x tcp4-listen:$listeningport,bind=$listeningaddr,reuseaddr,fork exec:"$0 proxy" & pid=$! echo $pid > $pidfile echo "$0 $mode started (pid=$pid)" elif [ "$mode" == "proxy" ]; cat - > $tmpfile # process $tmpfile before ssl connection. cat $tmpfile | socat -t 100 -lf $logf -d - openssl:$host rm -f $tmpfile
everything fine when run:
$ cat somefile | myscript.sh proxy | xxd
the problem raise when connect socat listener test script:
my $file = $argv[0]; $fsize = -s $file; $socket = io::socket::inet->new("127.0.0.1:$port") or die "couldn't connect remote host: $!"; $socket->autoflush(1); binmode($socket); open (file,$file); binmode(file); $buffer ; while(sysread(file, $buffer, $blocksize)) { print $socket $buffer ; } print "sent\n" ; close (file) ; $answer = <$socket>; if (defined($answer)) { print $answer; # never reached print "...\n" ; } else { die "connection reset peer\n"; }
in myscript.sh, blocks on line:
cat - > $tmpfile
in test script, blocks on line:
my $answer = <$socket>;
at point, info has been received socat listener (checked tcpdump).
however, when ctrl+c test script before socat timeout, info goes through pipe (i.e., ssl server contacted).
what doing wrong?
update: tips cat , eof. time being, have worked around problem so:
timeout 0.2 cat -u - > $tmpfile 2>>/dev/null # process $tmpfile before ssl connection. cat $tmpfile | socat -t 100 -lf $logf -d - openssl:$host
it's ugly, , waste 0.2 seconds, hope find improve solution. job now. 2>>/dev/null part because aix complains invalid counter (related timeout command).
my first thought there no linefeed in info you're trying receive cat -
or <stdin>
. both commands in default behavior homecoming info 1 time have linefeed or buffers of file-descriptor total (4kb default in linux).
perl bash ssl aix socat
No comments:
Post a Comment