In trying to verify the proper use of fcntl (so that I can set a socket file descriptor to non-blocking), I stumbled upon the above curiosity. When I run the above code, the output generated is#!/usr/bin/perl -w use Fcntl; # Experimenting with fcntl system call ## open this file open( FH, ">>fcntl.pl" ); $cur_opts = fcntl( FH, &F_GETFL, 0 ); # The print statement of death.... # print "cur_opts -> $cur_opts\n"; $rc = fcntl( FH, &F_SETFL, $cur_opts ); # "fixes" The print statement of death... #$rc = fcntl( FH, &F_SETFL, $cur_opts & 0xffffffff ); print "rc -> $rc\n"; $new_opts = fcntl( FH, &F_GETFL, 0 ); print "new_opts -> $new_opts\n"; if ( $new_opts != $cur_opts ) { print "ERROR\n"; } else { print "Calling F_SETFL with F_GETGL return value succeeded.\n"; } print "new_opts -> $new_opts cur_opts -> $cur_opts\n";
However, if I un-comment out the "print statement of death" line (see code above), I get the following output:rc -> 0 but true new_opts -> 1025 Calling F_SETFL with F_GETGL return value succeeded. new_opts -> 1025 cur_opts -> 1025
What I want to know, then, is what crime against nature have I committed by printing out the value of $cur_opts. Or, more importantly, how can I avoid this type of problem in the future? Note that masking off the 32 low order bits in the subsequent F_SETFL call allowed me to include the print line of death. Thanks for your assistance/explanation,cur_opts -> 1025 rc -> 0 but true new_opts -> 8193 ERROR new_opts -> 8193 cur_opts -> 1025V@S@ÿÿÿÿ0ÿÿÿÿÿÿÿÿHÿÿÿÿ N@
Edit by tye, add CODE tags, remove BR
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |