Virt/Connection/TCP.pm untested

filter: Statementstmt 0.0% 0 / 55 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 10 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 0.0% 0 / 11 Podpod n/a totaltotal 0.0% 0 / 86 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 ####################################################################
2 #
3 # This file was generated using XDR::Parse version v1.0.1
4 # and LibVirt version v12.9.0
5 #
6 # Don't edit this file, use the source template instead
7 #
8 # ANY CHANGES HERE WILL BE LOST !
9 #
10 ####################################################################
11  
12  
13 use v5.26;
14 use warnings;
15 use experimental 'signatures';
16 use Future::AsyncAwait;
17 use Object::Pad ':experimental(inherit_field)';
18  
19 class Sys::Async::Virt::Connection::TCP v0.6.9;
20  
21 inherit Sys::Async::Virt::Connection '$_in', '$_out';
22  
23 use Carp qw(croak);
24 use Future::IO;
25 use IO::Socket::IP;
26 use Log::Any qw($log);
27  
28 use Protocol::Sys::Virt::URI; # imports parse_url
29  
30 my $use_async_resolver = eval { require Future::IO::Resolver; 1; };
31  
32 field $_url :param :reader :inheritable;
33 field $_readonly :param = undef;
34 field $_socket :param :inheritable = undef;
35  
36  
37 ### workaround methods while transitive inheritace doesn't work in Object::Pad
38 ### See: RT#172999
39  
40 method _set_in($in) {
41 $_in = $in;
42 }
43  
44 method _set_out($out) {
45 $_out = $out;
46 }
47  
48 ###
49  
50 method _default_port() {
51 return 16509;
52 }
53  
54 async method close() {
55 # Work around for Future::IO which doesn't
56 # like handles being closed when there are
57 # outstanding read/write requests (causing
58 # warnings of undefined values)
59 $self->_finalize_io();
60 # When Future::IO and/or IO::Async are changed
61 # (ready_for_input() is where this happens),
62 # the handle *can* be closed.
63 # $_in->close;
64 return;
65 }
66  
67 async method connect() {
68 # disect URL
69 my %components = parse_url( $_url );
70  
71 if ($use_async_resolver) {
72 my ($address) = await Future::IO::Resolver->getaddrinfo(
73 host => $components{host},
74 service => ($components{port} // $self->_default_port),
75 socktype => SOCK_STREAM,
76 );
77 socket( $_socket,
78 $address->{family},
79 $address->{socktype},
80 $address->{protocol} )
81 or die;
82 await Future::IO->connect( $_socket, $address->{addr} );
83 }
84 else {
85 my ($err, @addresses) = IO::Socket::IP::getaddrinfo(
86 $components{host},
87 ($components{port} // $self->_default_port),
88 { socktype => SOCK_STREAM }
89 );
90 die $err if $err;
91  
92 $_socket = IO::Socket::IP->new(
93 Type => SOCK_STREAM,
94 PeerAddrInfo => \@addresses,
95 )
96 or die "Failed to connect socket: $!";
97 }
98  
99 $_in = $_out = $_socket;
100 }
101  
102 method is_secure() {
103 return 0;
104 }
105  
106 1;
107  
108  
109 __END__