Hi, all -

I am trying to write both sever/client that using non blocking socket.
I am not using BIO based read/write. Here is what my code look like - The
code is almost
same as the serv.cpp and cli.cpp under demos/ssl, except I am seting non
blocking
option (O_NONBLOCK)

SERVER:
========
        SSL             *ssl;
        SSL_CTX         *ctx;

        listen_sd  = socket(..)
        flag = fcntl(listen_sd, F_GETFL);
        fcntl(listen_sd, F_SETFL, flag | O_NONBLOCK);
        bind(listen_sd, ...);
        listen(listen_sd,...);
        select(listen_sd+1, ...);

        sd = accept(listen_sd, ...);

        flag = fcntl(sd, F_GETFL);
        fcnt(sd, F_SETFL, flag | O_NONBLOCK);

        ctx = SSL_CTX_new(...);
        ssl = SSL_new(ctx);
        SSL_set_fd(ssl, sd);
        SSL_accept(ssl);

        for (;;) {
           SSL_read(ssl);
           SSL_write(ssl);
        }

CLIENT:
======

        sd = socket(...);
        flag = fcntl(sd, F_GETFL);
        fcnt(sd, F_SETFL, flag | O_NONBLOCK);

        connect(sd,...);

        ctx = SSL_CTX_new(...);
        ssl = SSL_new(ctx);
        SSL_set_fd(ssl, sd);
        SSL_connect(ssl);

        SSL_write(ssl);
        SSL_read(ssl);

The problem is that SSL_accept() failed (return -1). I could not get error
code witn ERR_print_errors and I
don't know why.  Does anyone know what's wrong with this piece of code or if
it makes sense? The reason
I am not using BIO is that I would like to manage both non-SSL and SSL
connection over the socket.
Can I do something like that? Any help is appreciated.

Miha

______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    [EMAIL PROTECTED]
Automated List Manager                           [EMAIL PROTECTED]

Reply via email to