Hi,

I'm struggling to write a simple forking server. What I have works but eventually crashes with the following messages:

Error in connection
9130:error:02008018:system library:accept:Too many open files:b_sock.c:735:
9130:error:20065064:BIO routines:BIO_accept:accept error:b_sock.c:736:

Here is an abridged code snippet:

8<----------------------------------------------------------------------------------------------------------------------
    sbio = BIO_push(bbio, sbio);
    acpt=BIO_new_accept("4433");
    BIO_set_accept_bios(acpt,sbio);
    /* Setup accept BIO */
    if(BIO_do_accept(acpt) <= 0) {
        return 0;
    }
    /* Now wait for incoming connection */
    while(1) {
        if(BIO_do_accept(acpt) <= 0) {
            return 0;
        }
        sbio = BIO_pop(acpt);
        pid = fork ();
        if (pid == 0) {     // child process (works fine)
            if(BIO_do_handshake(sbio) <= 0) {
                return 0;
            }
            BIO_puts(sbio, "Hello\r\n");
            BIO_flush(sbio);
            BIO_free_all(sbio);
            exit (0);
} else { // parent process (eventually crashes after many connections) // <----------------- What must I do here, if anything to free memory, etc ?
        }
    }
    BIO_free_all(acpt);
8<----------------------------------------------------------------------------------------------------------------------

I have a simple client to connect to it, but if I connect enough times, the server code (above) eventually crashes with the errors shown above. I think that the problem is that after it forks, the parent process should release some resource, but I don't understand the BIO_* interface well enough to know what to do.

I would really appreciate any help, as I'm totally stuck here.

Many thanks,
Thomas
______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    openssl-users@openssl.org
Automated List Manager                           majord...@openssl.org

Reply via email to