Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Non-Blocking Sockets

by Anonymous Monk
on Sep 20, 2003 at 14:02 UTC ( #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?

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (13)
As of 2018-10-22 14:03 GMT
Find Nodes?
    Voting Booth?
    When I need money for a bigger acquisition, I usually ...

    Results (119 votes). Check out past polls.

    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!