예제 #1
0
void swPort_free(swListenPort *port)
{
#ifdef SW_USE_OPENSSL
    if (port->ssl)
    {
        if (port->ssl_context)
        {
            swSSL_free_context(port->ssl_context);
        }
        sw_free(port->ssl_option.cert_file);
        sw_free(port->ssl_option.key_file);
        if (port->ssl_option.client_cert_file)
        {
            sw_free(port->ssl_option.client_cert_file);
        }
    }
#endif

    close(port->sock);

    //remove unix socket file
    if (port->type == SW_SOCK_UNIX_STREAM || port->type == SW_SOCK_UNIX_DGRAM)
    {
        unlink(port->host);
    }
}
예제 #2
0
파일: Client.c 프로젝트: 921299/swoole-src
static int swClient_close(swClient *cli)
{
    int fd = cli->socket->fd;
    int ret;

#ifdef SW_USE_OPENSSL
    if (cli->open_ssl && cli->ssl_context)
    {
        if (cli->socket->ssl)
        {
            swSSL_close(cli->socket);
        }
        swSSL_free_context(cli->ssl_context);
        if (cli->ssl_cert_file)
        {
            free(cli->ssl_cert_file);
        }
        if (cli->ssl_key_file)
        {
            free(cli->ssl_key_file);
        }
    }
#endif

    //clear buffer
    if (cli->buffer)
    {
        swString_free(cli->buffer);
        cli->buffer = NULL;
    }

    if (cli->async)
    {
        //remove from reactor
        SwooleG.main_reactor->del(SwooleG.main_reactor, fd);
        cli->socket->closed = 1;
        //onClose callback
        if (cli->socket->active && cli->onClose)
        {
            cli->onClose(cli);
        }
        ret = swReactor_close(SwooleG.main_reactor, fd);
    }
    else
    {
        bzero(cli->socket, sizeof(swConnection));
        ret = close(fd);
    }

    cli->closed = 1;

    if (cli->type == SW_SOCK_UNIX_DGRAM)
    {
        unlink(cli->socket->info.addr.un.sun_path);
    }

    return ret;
}
예제 #3
0
static int swClient_close(swClient *cli)
{
    int fd = cli->socket->fd;
    assert(fd != 0);
#ifdef SW_USE_OPENSSL
    if (cli->open_ssl && cli->ssl_context)
    {
        if (cli->socket->ssl)
        {
            swSSL_close(cli->socket);
        }
        swSSL_free_context(cli->ssl_context);
        if (cli->ssl_cert_file)
        {
            free(cli->ssl_cert_file);
        }
        if (cli->ssl_key_file)
        {
            free(cli->ssl_key_file);
        }
    }
#endif
    //clear buffer
    if (cli->buffer)
    {
        swString_free(cli->buffer);
        cli->buffer = NULL;
    }
    if (cli->type == SW_SOCK_UNIX_DGRAM)
    {
        unlink(cli->socket->info.addr.un.sun_path);
    }
    if (cli->socket->closed)
    {
        return SW_OK;
    }
    cli->socket->closed = 1;
    if (cli->async)
    {
        //remove from reactor
        if (!cli->socket->removed && SwooleG.main_reactor)
        {
            SwooleG.main_reactor->del(SwooleG.main_reactor, fd);
        }
        //onClose callback
        if (cli->socket->active && cli->onClose)
        {
            cli->socket->active = 0;
            cli->onClose(cli);
        }
    }
    else
    {
        cli->socket->active = 0;
    }
    return close(fd);
}