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

In reply to Net::Server blocks on non-blocking socket with SSL by cavac

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.