From f643e3f3103b73c60f9a0106754e060d3ea6d707 Mon Sep 17 00:00:00 2001 From: Dirk Koopman Date: Tue, 17 Jun 2014 00:54:02 +0100 Subject: [PATCH] get sh/db0sdx working with mojo --- cmd/show/db0sdx.pl | 16 ++++++++++------ perl/AsyncMsg.pm | 16 +++++++++++++++- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/cmd/show/db0sdx.pl b/cmd/show/db0sdx.pl index b7574761..64c6f3bf 100644 --- a/cmd/show/db0sdx.pl +++ b/cmd/show/db0sdx.pl @@ -13,20 +13,21 @@ sub on_disc my $conn = shift; my $dxchan = shift; my @out; + +# $DB::single = 1; - $conn->{sdxin} .= $conn->{msg}; # because there will be stuff left in the rx buffer because it isn't \n terminated dbg("db0sdx in: $conn->{sdxin}") if isdbg('db0sdx'); my ($info) = $conn->{sdxin} =~ m|([^<]*)|; - dbg("info: $info"); +# dbg("db0sdx info: $info"); my $prefix = $conn->{prefix} || ''; my @in = split /[\r\n]/, $info if $info; if (@in && $in[0]) { - dbg("in qsl"); +# dbg("db0sdx: in qsl"); push @out, map {"$prefix$_"} @in; } else { - dbg("in fault"); +# dbg("db0sdx: in fault"); ($info) = $conn->{sdxin} =~ m|([^<]*)|; push @out, "$prefix$info" if $info; push @out, $dxchan->msg('e3', 'DB0SDX', $conn->{sdxline}) unless @out; @@ -39,6 +40,8 @@ sub process my $conn = shift; my $msg = shift; +# $DB::single = 1; + $conn->{sdxin} .= "$msg\n"; dbg("db0sdx in: $conn->{sdxin}") if isdbg('db0sdx'); @@ -69,7 +72,8 @@ sub handle ); - my $lth = length($s)+1; +# $s .= "\n"; + my $lth = length($s); Log('call', "$call: show/db0sdx $line"); my $conn = AsyncMsg->post($self, $target, "$path$suffix", prefix => 'sdx> ', filter => \&process, @@ -81,7 +85,7 @@ sub handle on_disc => \&on_disc); if ($conn) { - $conn->{sdxcall} = $line; + $conn->{sdxline} = $line; push @out, $self->msg('m21', "show/db0sdx"); } else { push @out, $self->msg('e18', 'DB0SDX Database server'); diff --git a/perl/AsyncMsg.pm b/perl/AsyncMsg.pm index cb087876..b1875d97 100644 --- a/perl/AsyncMsg.pm +++ b/perl/AsyncMsg.pm @@ -130,6 +130,20 @@ sub _getpost # $tx->on(error => sub { $conn->_error(@_); }); # $tx->on(finish => sub { $conn->disconnect; }); + $ua->on(start => sub { + my ($ua, $tx) = @_; + my $data = delete $args{data}; + while (my ($k, $v) = each %args) { + dbg("AsyncMsg: attaching header $k: $v") if isdbg('async'); + $tx->req->headers->header($k => $v); + } + if (defined $data) { + dbg("AsyncMsg: body ='$data'") if isdbg('async'); + $tx->req->body($data); + } + }); + + $ua->start($tx => sub { $conn->handle_getpost(@_) }); @@ -251,7 +265,7 @@ sub disconnect my $dxchan = DXChannel::get($conn->{caller}); if ($dxchan) { no strict 'refs'; - $ondisc->($conn, $dxchan) + $ondisc->($conn, $dxchan); } } delete $conn->{mojo}; -- 2.34.1