@@ -17,7 +17,7 @@ our @EXPORT = qw(
1717 packet_compare_lists
1818 packet_bin_read
1919 packet_txt_read
20- packet_required_key_val_read
20+ packet_key_val_read
2121 packet_bin_write
2222 packet_txt_write
2323 packet_flush
@@ -68,28 +68,33 @@ sub packet_bin_read {
6868
6969sub remove_final_lf_or_die {
7070 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 ;
7473 }
75- return $buf ;
74+ die " A non-binary line MUST be terminated by an LF.\n "
75+ . " Received: '$buf '" ;
7676}
7777
7878sub packet_txt_read {
7979 my ( $res , $buf ) = packet_bin_read();
80- unless ( $res == -1 or $buf eq ' ' ) {
80+ if ( $res != -1 and $buf ne ' ' ) {
8181 $buf = remove_final_lf_or_die($buf );
8282 }
8383 return ( $res , $buf );
8484}
8585
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 {
8792 my ( $key ) = @_ ;
8893 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 ) ;
9196 }
92- return ( $res , $buf ) ;
97+ die " bad $key : ' $buf ' " ;
9398}
9499
95100sub packet_bin_write {
0 commit comments