Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Non-blocking sockets with Net::Server and SSL

by noxxi (Pilgrim)
on Apr 09, 2015 at 21:06 UTC ( [id://1122995]=note: print w/replies, xml ) Need Help??


in reply to Non-blocking sockets with Net::Server and SSL

>     STDIN->blocking(0);

That part is the problem. Net::Server tries to handle SSL in a special way but this way is not working with the code you use. The blocking(0) will not be done on the socket to the client, but instead on fd 0 which is at this moment /dev/null. Thus it will not have the desired effect.

One way to deal with the problem is to reach into the internals of Net::Server to get access to the real file descriptor behind STDIN:

tied(*STDIN)->[0]->blocking(0);
A better way is to use the file descriptor which is given to the process_request function:
sub process_request {
    my ($self,$fd) = @_;
    $fd->blocking(0);
In both variants the real socket will be set non-blocking.

Apart from that, note that the SSL handshake will still be done blocking by Net::Server.

  • Comment on Re: Non-blocking sockets with Net::Server and SSL

Replies are listed 'Best First'.
Re^2: Non-blocking sockets with Net::Server and SSL
by cavac (Parson) on Apr 09, 2015 at 21:22 UTC

    It works! It really works! You Madam/Sir/Other are my hero!

    I just tried

    my ($self,$fd) = @_; $fd->blocking(0);
    and it works!

    You really deserve a hug! I've been trying for the last ten days to fix my websocket implementation and you did it in two lines!

    Very much appreciated!

    "For me, programming in Perl is like my cooking. The result may not always taste nice, but it's quick, painless and it get's food on the table."

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (2)
As of 2024-04-19 20:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found