I'm messing around with SSL.File in a threaded server, and have run
into a strange difficulty. The object defaults to nonblocking mode,
which is fine; but how do I set it to blocking mode? Here's my current
code:

//sock is a straight Stdio.File initially

string handshake = sock->read(9, 1);
if (sizeof(handshake) >= 2 && handshake[0] == 0x16 && handshake[1] == 0x03)
{
    //Probable SSL handshake
    Pike.SmallBackend backend = Pike.SmallBackend();
    sock->set_backend(backend);
    sock = SSLFile(sock, SSL.Context());
    write("nonblocking_mode: %O\n", sock->is_nonblocking());
    sock->accept(handshake);
    backend->call_out(sock->set_blocking, 0);
    while (sock->is_nonblocking())
        backend(1.0);
}

But this depends on being able to figure out when the socket has gone
into blocking mode. To do that, I'm using my own subclass of SSL.File:

class SSLFile
{
    inherit SSL.File;
    int is_nonblocking() {return nonblocking_mode;}
}

to get around the fact that nonblocking_mode (the exact thing I'm
looking for!) is flagged 'protected'. Why is this? And would an
is_nonblocking method be a reasonable addition?

ChrisA

Reply via email to