in reply to Socket descriptor passed across fork -- hanging

So what does it mean when the following code:

$! = 0; $res = $sock->read($data, 255); # $res: #chars, or 0 for EOF, or undef for error $err = $!; $iologger->debug("bufrd res " . safe($res) . ": " . safe($data) . " err $err");

Logs this:

2011-10-13 09:21:39,782 DEBUG kcmdproxy.child.io(30674):366 bufrd res +<<127>>: <<simkserver<sp>30665<sp>port<sp>2001<sp>client<sp>127.0.0.1 +<sp>command<sp>special<lf>1,8,7,2,13,1,12<lf>13,5,11,10,8,0,13<lf>5,2 +,11,4,5,10,5<lf>3,5,7,10,12,2,12<lf>>> err Resource temporarily unava +ilable

The socket call returned 127, which should be a number of characters (and looks about right). And it also set $! (which I had carefully set to 0 before the call). There isn't threading going on, and the signal handling is at the level of setting one variable in the handler, so nothing else should be interrupting to set $!. I suppose I could localize it, just as a test, to see if this still happens, but I don't see how something else can be getting in to set it. Does the $! value mean anything in this case, or is it just garbage?

Replies are listed 'Best First'.
Re^2: Socket descriptor passed across fork -- hanging
by SuicideJunkie (Vicar) on Oct 13, 2011 at 15:38 UTC

    $! only has meaning if the operation failed. After a success its value could be anything.

    perldoc says: If used numerically, yields the current value of the C errno variable, or in other words, if a system or library call fails, it sets this variable. This means that the value of $! is meaningful only immediately after a failure: