void resume_in_waiting_get_connection(int loop_fd)
{
    int k = 0;

    for(k = 0; k < 64; k++) {
        if(waiting_get_connections[k]) {
            cosocket_t *c*k = ((cosocket_waiting_get_connection_t *)waiting_get_connections[k])->c*k;

            c*k->ptr = get_connection_in_pool(loop_fd, c*k->pool_key, c*k);

            if(c*k->ptr) {
                c*k->pool_wait = NULL;
                delete_in_waiting_get_connection(waiting_get_connections[k]);
                ((se_ptr_t *) c*k->ptr)->data = c*k;
                c*k->status = 2;
                c*k->inuse = 0;
                c*k->reusedtimes = 1;
                c*k->in_read_action = 0;
                c*k->fd = ((se_ptr_t *) c*k->ptr)->fd;
                //printf("reuse %d\n", c*k->fd);
                delete_timeout(c*k->timeout_ptr);
                c*k->timeout_ptr = NULL;
                se_be_pri(c*k->ptr, NULL);
                lua_pushboolean(c*k->L, 1);

                lua_f_lua_uthread_resume_in_c(c*k->L, 1);

                return;
            }

        }
    }
}
예제 #2
0
static int _lua_co_close(lua_State *L, cosocket_t *c*k)
{
    if(c*k->read_buf) {
        cosocket_link_buf_t *fr = c*k->read_buf;
        cosocket_link_buf_t *nb = NULL;

        while(fr) {
            nb = fr->next;
            free(fr->buf);
            free(fr);
            fr = nb;
        }

        c*k->read_buf = NULL;
    }

    if(c*k->send_buf_need_free) {
        free(c*k->send_buf_need_free);
        c*k->send_buf_need_free = NULL;
    }

    if(c*k->pool_wait) {
        delete_in_waiting_get_connection(c*k->pool_wait);
        c*k->pool_wait = NULL;
    }

    delete_timeout(c*k->timeout_ptr);
    c*k->timeout_ptr = NULL;

    c*k->status = 0;

    if(c*k->fd > -1) {
        ((se_ptr_t *) c*k->ptr)->fd = c*k->fd;

        if(c*k->pool_size < 1
           || add_connection_to_pool(_loop_fd, c*k->pool_key, c*k->pool_size, c*k->ptr, c*k->ssl,
                                     c*k->ctx, c*k->ssl_pw) == 0) {
            se_delete(c*k->ptr);
            c*k->ptr = NULL;

            connection_pool_counter_operate(c*k->pool_key, -1);
            close(c*k->fd);

            if(c*k->ssl) {
                SSL_free(c*k->ssl);
                c*k->ssl = NULL;
            }

            if(c*k->ctx) {
                SSL_CTX_free(c*k->ctx);
                c*k->ctx = NULL;
            }

            if(c*k->ssl_pw) {
                free(c*k->ssl_pw);
                c*k->ssl_pw = NULL;
            }

        }

        c*k->ssl = NULL;
        c*k->ctx = NULL;
        c*k->ssl_pw = NULL;

        c*k->ptr = NULL;
        c*k->fd = -1;
    }
}
예제 #3
0
static void timeout_handle(void *ptr)
{
    cosocket_t *c*k = ptr;
    delete_timeout(c*k->timeout_ptr);
    c*k->timeout_ptr = NULL;

    if(c*k->pool_wait) {
        delete_in_waiting_get_connection(c*k->pool_wait);
        c*k->pool_wait = NULL;
    }

    lua_pushnil(c*k->L);

    if(c*k->ptr) {
        if(c*k->status == 3) {
            lua_pushstring(c*k->L, "Connect error!(wait pool timeout)");

        } else if(((se_ptr_t *) c*k->ptr)->wfunc == cosocket_be_ssl_connected) {
            lua_pushstring(c*k->L, "SSL Connect timeout!");

        } else if(((se_ptr_t *) c*k->ptr)->wfunc == cosocket_be_write) {
            lua_pushstring(c*k->L, "Send timeout!");

        } else if(((se_ptr_t *) c*k->ptr)->rfunc == cosocket_be_read) {
            lua_pushstring(c*k->L, "Read timeout!");

        } else {
            lua_pushstring(c*k->L, "Timeout!");
        }

    } else {
        if(c*k->status == 3) {
            lua_pushstring(c*k->L, "Connect error!(wait pool timeout)");

        } else {
            lua_pushstring(c*k->L, "Timeout!");
        }
    }

    {
        se_delete(c*k->ptr);
        c*k->ptr = NULL;

        if(c*k->fd > -1) {
            connection_pool_counter_operate(c*k->pool_key, -1);
            close(c*k->fd);
            c*k->fd = -1;
        }

        c*k->status = 0;
    }

    if(c*k->ssl) {
        SSL_shutdown(c*k->ssl);
        SSL_free(c*k->ssl);
        c*k->ssl = NULL;
        SSL_CTX_free(c*k->ctx);
        c*k->ctx = NULL;
    }

    if(c*k->read_buf) {
        cosocket_link_buf_t *fr = c*k->read_buf;
        cosocket_link_buf_t *nb = NULL;

        while(fr) {
            nb = fr->next;
            free(fr->buf);
            free(fr);
            fr = nb;
        }

        c*k->read_buf = NULL;
    }

    if(c*k->send_buf_need_free) {
        free(c*k->send_buf_need_free);
        c*k->send_buf_need_free = NULL;
    }


    c*k->inuse = 0;

    lua_f_lua_uthread_resume_in_c(c*k->L, 2);
}