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?
|
|---|
| 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 |