Looks like it needs a BIO_free_all(bio) or something similair.
-----Original Message-----
From: owner-openssl-us...@openssl.org
[mailto:owner-openssl-us...@openssl.org]on Behalf Of Matthew Allen
Sent: Wednesday, April 21, 2010 5:18 AM
To: openssl-users@openssl.org
Subject: Socket left in CLOSE_WAIT state...


Hi,

My code leaves sockets in the CLOSE_WAIT state after I free the SSL
connection (running on windows XP with  OpenSSL 0.9.8e). After I'm done with
the connection I call SSL_shutdown and SSL_free, but that doesn't close the
socket on the client side. My code's probably wrong, so tell me what I
should change?

#include <stdlib.h>
#include "windows.h"
#include "openssl/ssl.h"

char Hostname[] = "imap.gmail.com";
int Port = 993;

int main(int args, char **arg)
{
    printf("OpenSSL Test\n");

    SSL_library_init();
    SSL_load_error_strings();
    ERR_load_BIO_strings();
    OpenSSL_add_all_algorithms();

    SSL_CTX *Ctx = SSL_CTX_new(SSLv23_client_method());
    if (Ctx)
    {
        SSL *Ssl = 0;
        BIO *Bio = BIO_new_ssl_connect(Ctx);
        if (Bio)
        {
            BIO_get_ssl(Bio, &Ssl);
            if (Ssl)
            {
                SSL_set_mode(Ssl, SSL_MODE_AUTO_RETRY);
                BIO_set_conn_hostname(Bio, Hostname);
                BIO_set_conn_int_port(Bio, &Port);

                if (BIO_do_connect(Bio) > 0)
                {
                    printf("Connected to '%s' using SSL\n", Hostname);

                    char Data[256];
                    char *Cmd = "A0001 CAPABILITY\r\n";
                    int w = SSL_write(Ssl, Cmd, strlen(Cmd));
                    if (w > 0)
                    {
                        printf("Wrote %i bytes.\n", w);

                        int r = SSL_read(Ssl, Data, sizeof(Data));
                        if (r > 0)
                        {
                            printf("Got %i bytes.\n", r);
                        }
                        else printf("SSL_read failed.\n");
                    }
                    else printf("SSL_write failed.\n");
                }
                else printf("BIO_do_connect failed.\n");
            }
            else printf("BIO_get_ssl failed.\n");
        }
        else printf("BIO_new_ssl_connect failed.\n");

        if (Ssl)
        {
            SSL_shutdown(Ssl);
            SSL_free(Ssl);
        }

        /* At this point I expect the socket should have disappeared, but
it's still there
        hanging around in CLOSE_WAIT... why? */

        SSL_CTX_free(Ctx);
    }

    return 0;
}





Thanks
--
Matthew Allen

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

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

Reply via email to