Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Non-Blocking Sockets

by Anonymous Monk
on Sep 20, 2003 at 14:02 UTC ( [id://292856]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

From the perl cookbook, i am using the following code to make a socket nonblocking.
$flags = fcntl($socket, F_GETFL, 0) or die "Can't get flags for socket: $!\n"; fcntl($socket, F_SETFL, $flags | O_NONBLOCK) or die "Can't make socket nonblocking: $!\n";

Sometimes this actually kills the server while there are still active connections to it. So, instead of doing an "or die" i need to handle this a different way.

My question is 2 fold.
1) What causes this to fail? Is it server side, client side, or both?
2) Whats the best way to handle this? Passing it to another function to clean everything up in regards to that one socket?

Replies are listed 'Best First'.
Re: Non-Blocking Sockets
by Anonymous Monk on Sep 20, 2003 at 16:51 UTC

    I haven't done it that way. I've used IO::Socket::INET which provides the Blocking method. If it's set to 0, the socket become non-blocking.

    Anonymously yours,
    Anonymous Nun

Re: Non-Blocking Sockets ($!)
by tye (Sage) on Sep 22, 2003 at 15:07 UTC
    What causes this to fail?

    You are in a better position to determine this than we are because you probably know what was reported for $! while we do not. Perhaps you'd get better results if you shared that information.

    Normally I'd also make a wild guess, but in this case, lacking that item, all of the guesses just seem too wild ($socket has been closed, ...).

    Usually I wouldn't post this response but it has been days and you haven't gotten an answer to this part of your question.

                    - tye

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://292856]
Approved by jdtoronto
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (2)
As of 2024-04-26 07:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found