+sub mux_eof {
+ my ($self, $mux, $fh, $input) = @_;
+
+ my $queue_info = &$lookup_queue_info($self, $fh);
+ return if !$queue_info;
+
+ my $sname = $queue_info->{sname};
+ my $vmid = $queue_info->{vmid};
+ my $qga = $queue_info->{qga};
+
+ my $curcmd = $queue_info->{current};
+ die "unable to lookup current command for VM $vmid ($sname)\n" if !$curcmd;
+
+ if ($qga && $qga_allow_close_cmds->{$curcmd->{execute}}) {
+
+ return if $$input !~ s/^.*\xff([^\n]+})\r?\n(.*)$/$2/so;
+
+ my $raw = $1;
+
+ eval {
+ my $obj = from_json($raw);
+
+ my $cmdid = $obj->{'return'};
+ die "received responsed without command id\n" if !$cmdid;
+
+ delete $queue_info->{current};
+
+ if (my $callback = $curcmd->{callback}) {
+ &$callback($vmid, undef);
+ }
+ };
+ if (my $err = $@) {
+ $queue_info->{error} = $err;
+ }
+
+ &$close_connection($self, $queue_info);
+
+ if (scalar(@{$queue_info->{cmds}}) && !$queue_info->{error}) {
+ $queue_info->{error} = "Got EOF but command queue is not empty.\n";
+ }
+ }
+}
+