@@ -17,7 +17,7 @@ our @EXPORT = qw(
17
17
packet_compare_lists
18
18
packet_bin_read
19
19
packet_txt_read
20
- packet_required_key_val_read
20
+ packet_key_val_read
21
21
packet_bin_write
22
22
packet_txt_write
23
23
packet_flush
@@ -68,28 +68,33 @@ sub packet_bin_read {
68
68
69
69
sub remove_final_lf_or_die {
70
70
my $buf = shift ;
71
- unless ( $buf =~ s /\n $// ) {
72
- die " A non-binary line MUST be terminated by an LF.\n "
73
- . " Received: '$buf '" ;
71
+ if ( $buf =~ s /\n $// ) {
72
+ return $buf ;
74
73
}
75
- return $buf ;
74
+ die " A non-binary line MUST be terminated by an LF.\n "
75
+ . " Received: '$buf '" ;
76
76
}
77
77
78
78
sub packet_txt_read {
79
79
my ( $res , $buf ) = packet_bin_read();
80
- unless ( $res == -1 or $buf eq ' ' ) {
80
+ if ( $res != -1 and $buf ne ' ' ) {
81
81
$buf = remove_final_lf_or_die($buf );
82
82
}
83
83
return ( $res , $buf );
84
84
}
85
85
86
- sub packet_required_key_val_read {
86
+ # Read a text packet, expecting that it is in the form "key=value" for
87
+ # the given $key. An EOF does not trigger any error and is reported
88
+ # back to the caller (like packet_txt_read() does). Die if the "key"
89
+ # part of "key=value" does not match the given $key, or the value part
90
+ # is empty.
91
+ sub packet_key_val_read {
87
92
my ( $key ) = @_ ;
88
93
my ( $res , $buf ) = packet_txt_read();
89
- unless ( $res == -1 or ( $buf =~ s / ^$key=// and $buf ne ' ' ) ) {
90
- die " bad $key : ' $buf ' " ;
94
+ if ( $res == -1 or ( $buf =~ s / ^$key=// and $buf ne ' ' ) ) {
95
+ return ( $res , $buf ) ;
91
96
}
92
- return ( $res , $buf ) ;
97
+ die " bad $key : ' $buf ' " ;
93
98
}
94
99
95
100
sub packet_bin_write {
0 commit comments