Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Net::Server blocks on non-blocking socket with SSL

by cavac (Parson)
on Mar 31, 2015 at 11:36 UTC ( [id://1121965]=perlquestion: print w/replies, xml ) Need Help??

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

I'm using Net::Server for a lot of stuff, including my own Websocket implementation. For this, i switch the socket to non-blocking like this:

my $webflags = 0; fcntl(STDIN, F_GETFL, $webflags) or die "Couldn't get flags for HANDLE : $!\n"; $webflags |= O_NONBLOCK; fcntl(STDIN, F_SETFL, $webflags) or die "Couldn't set flags for HANDLE: $!\n";

Then i do bytewise reads like this:

my $data = ''; my $buf; while(1) { eval { my $status = sysread(STDIN, $buf, 1); }; last if(!length($buf)); $data .= $buf; $buf = undef; }

Works quite nicely, and yes, i'm aware that this isn't the most efficient way to do it. But it is nice and debugable.

The problem is: When SSL is active, sysread() blocks, but it shouldn't.

For SSL i use something like this (and yes, it works for most use cases, since i'm only using non-blocking sockets in websockets):

$server->run( [...some other stuff...] proto => 'ssl', usessl=>1, SSL_key_file=> $config->{server}->{sslkey}, SSL_cert_file=> $config->{server}->{sslcert}, [...some other stuff...] );

What am i doing wrong?

"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."

Replies are listed 'Best First'.
Re: Net::Server blocks on non-blocking socket with SSL
by noxxi (Pilgrim) on Mar 31, 2015 at 18:56 UTC
    Please provide more details, especially which versions of the libraries (Net::Server, IO::Socket::SSL) you are using, which operating system, Perl version etc. Preferable is also a simply program to reproduce the problem. And why don't you simply use the blocking method to switch to non-blocking mode?

Log In?
Username:
Password:

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

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

    No recent polls found