Exemplo n.º 1
0
int swReactor_close(swReactor *reactor, int fd)
{
    swConnection *socket = swReactor_get(reactor, fd);
    if (socket->out_buffer)
    {
        swBuffer_free(socket->out_buffer);
        socket->out_buffer = NULL;
    }

    if (socket->in_buffer)
    {
        swBuffer_free(socket->in_buffer);
        socket->in_buffer = NULL;
    }

#ifdef SW_USE_OPENSSL
    if (socket->ssl)
    {
        swSSL_close(socket);
    }
#endif

    bzero(socket, sizeof(swConnection));
    return close(fd);
}
Exemplo n.º 2
0
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;
}
Exemplo n.º 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);
}