Exemplo n.º 1
0
struct conn *
conn_get(void *owner)
{
    struct conn *conn;

    conn = _conn_get();
    if (conn == NULL) {
        return NULL;
    }

    conn->owner = owner;

    log_verb("get conn %p", conn);
    return conn;
}
Exemplo n.º 2
0
struct conn *
conn_get_proxy(void *owner)
{
    struct server_pool *pool = owner;
    struct conn *conn;

    conn = _conn_get(NULL);
    if (conn == NULL) {
        return NULL;
    }

    if (pool->redis) {
        conn->source_type = NC_SOURCE_TYPE_REDIS;
    } else {
        conn->source_type = NC_SOURCE_TYPE_MC;
    }

    conn->proxy = 1;

    conn->recv = proxy_recv;
    conn->recv_next = NULL;
    conn->recv_done = NULL;

    conn->send = NULL;
    conn->send_next = NULL;
    conn->send_done = NULL;

    conn->close = proxy_close;
    conn->active = NULL;

    conn->ref = proxy_ref;
    conn->unref = proxy_unref;

    conn->enqueue_inq = NULL;
    conn->dequeue_inq = NULL;
    conn->enqueue_outq = NULL;
    conn->dequeue_outq = NULL;
    conn->cb = NULL;

    conn->ref(conn, owner);

    log_debug(LOG_VVERB, "get conn %p proxy %d", conn, conn->proxy);

    return conn;
}
Exemplo n.º 3
0
struct conn *
conn_get_proxy(void *owner)
{
    struct server_pool *pool = owner;
    struct conn *conn;

    conn = _conn_get();
    if (conn == NULL) {
        return NULL;
    }

    conn->redis = pool->redis;

    conn->proxy = 1;

    conn->recv = proxy_recv;
    conn->recv_next = NULL;
    conn->recv_done = NULL;

    conn->send = NULL;
    conn->send_next = NULL;
    conn->send_done = NULL;

    conn->close = proxy_close;
    conn->active = NULL;
    conn->restore = proxy_restore;

    conn->ref = proxy_ref;
    conn->unref = proxy_unref;

    conn->enqueue_inq = NULL;
    conn->dequeue_inq = NULL;
    conn->enqueue_outq = NULL;
    conn->dequeue_outq = NULL;

    conn->ref(conn, owner);

    log_debug(LOG_VVERB, "get conn %p proxy %d", conn, conn->proxy);

    return conn;
}
Exemplo n.º 4
0
struct conn *
conn_get_manage(void *owner)
{
    struct conn *conn;

    conn = _conn_get(NULL);
    if (conn == NULL) {
        return NULL;
    }

    conn->source_type = NC_SOURCE_TYPE_PROXY;

    conn->proxy = 1;

    conn->recv = proxy_recv;
    conn->recv_next = NULL;
    conn->recv_done = NULL;

    conn->send = NULL;
    conn->send_next = NULL;
    conn->send_done = NULL;

    conn->close = proxy_close;
    conn->active = NULL;

    conn->ref = manage_ref;
    conn->unref = manage_unref;

    conn->enqueue_inq = NULL;
    conn->dequeue_inq = NULL;
    conn->enqueue_outq = NULL;
    conn->dequeue_outq = NULL;
    conn->cb = NULL;

    conn->ref(conn, owner);

    log_debug(LOG_VVERB, "get conn %p proxy %d", conn, conn->proxy);

    return conn;
}
Exemplo n.º 5
0
struct conn *
conn_get_notice(void *owner)
{
    struct conn *conn;

    conn = _conn_get(NULL);
    if (conn == NULL) {
        return NULL;
    }

    conn->notice = 1;

    conn->recv = notice_recv;
    conn->recv_next = NULL;
    conn->recv_done = NULL;

    conn->send = NULL;
    conn->send_next = NULL;
    conn->send_done = NULL;

    conn->close = NULL;
    conn->active = NULL;

    conn->ref = notice_ref;
    conn->unref = notice_unref;

    conn->enqueue_inq = NULL;
    conn->dequeue_inq = NULL;
    conn->enqueue_outq = NULL;
    conn->dequeue_outq = NULL;
    conn->cb = NULL;

    conn->ref(conn, owner);

    log_debug(LOG_VVERB, "get conn %p notice %d", conn, conn->notice);

    return conn;
}
Exemplo n.º 6
0
struct conn *
conn_get(void *owner, bool client, bool redis)
{
    struct conn *conn;

    conn = _conn_get();
    if (conn == NULL) {
        return NULL;
    }

    /* connection either handles redis or memcache messages */
    conn->redis = redis ? 1 : 0;

    conn->client = client ? 1 : 0;

    if (conn->client) {
        /*
         * client receives a request, possibly parsing it, and sends a
         * response downstream.
         */
        conn->recv = msg_recv;
        conn->recv_next = req_recv_next;
        conn->recv_done = req_recv_done;

        conn->send = msg_send;
        conn->send_next = rsp_send_next;
        conn->send_done = rsp_send_done;

        conn->close = client_close;
        conn->active = client_active;

        conn->ref = client_ref;
        conn->unref = client_unref;
        conn->need_auth = conn_need_auth(owner, redis);

        conn->enqueue_inq = NULL;
        conn->dequeue_inq = NULL;
        conn->enqueue_outq = req_client_enqueue_omsgq;
        conn->dequeue_outq = req_client_dequeue_omsgq;
        conn->post_connect = NULL;
        conn->swallow_msg = NULL;

        ncurr_cconn++;
    } else {
        /*
         * server receives a response, possibly parsing it, and sends a
         * request upstream.
         */
        struct server *server = (struct server *)owner;

        conn->recv = msg_recv;
        conn->recv_next = rsp_recv_next;
        conn->recv_done = rsp_recv_done;

        conn->send = msg_send;
        conn->send_next = req_send_next;
        conn->send_done = req_send_done;

        conn->close = server_close;
        conn->active = server_active;

        conn->ref = server_ref;
        conn->unref = server_unref;

        conn->need_auth = conn_need_auth(server->owner, redis);

        conn->enqueue_inq = req_server_enqueue_imsgq;
        conn->dequeue_inq = req_server_dequeue_imsgq;
        conn->enqueue_outq = req_server_enqueue_omsgq;
        conn->dequeue_outq = req_server_dequeue_omsgq;
        if (redis) {
          conn->post_connect = redis_post_connect;
          conn->swallow_msg = redis_swallow_msg;
        } else {
          conn->post_connect = memcache_post_connect;
          conn->swallow_msg = memcache_swallow_msg;
        }
    }

    conn->ref(conn, owner);
    log_debug(LOG_VVERB, "get conn %p client %d", conn, conn->client);

    return conn;
}
Exemplo n.º 7
0
struct conn *
conn_get(void *owner, bool client, unsigned source_type, struct conn_base *cb)
{
    struct conn *conn;

    conn = _conn_get(cb);
    if (conn == NULL) {
        return NULL;
    }

    /* this connection either handles redis or memcache messages */
    if (source_type == NC_SOURCE_TYPE_REDIS) {
        conn->source_type = NC_SOURCE_TYPE_REDIS;
    } else if (source_type == NC_SOURCE_TYPE_PROXY) {
        conn->source_type = NC_SOURCE_TYPE_PROXY;
    } else if (source_type == NC_SOURCE_TYPE_MC) {
        conn->source_type = NC_SOURCE_TYPE_MC;
    } else {
        NOT_REACHED();
    }

    conn->client = client ? 1 : 0;

    if (conn->client) {
        /*
         * client receives a request, possibly parsing it, and sends a
         * response downstream.
         */
        conn->recv = msg_recv;
        conn->recv_next = req_recv_next;
        conn->recv_done = req_recv_done;

        conn->send = msg_send;
        conn->send_next = rsp_send_next;
        conn->send_done = rsp_send_done;

        conn->close = client_close;
        conn->active = client_active;

        conn->ref = client_ref;
        conn->unref = client_unref;

        conn->enqueue_inq = NULL;
        conn->dequeue_inq = NULL;
        conn->enqueue_outq = req_client_enqueue_omsgq;
        conn->dequeue_outq = req_client_dequeue_omsgq;
        conn->post_connect = NULL;
        conn->swallow_msg = NULL;

        if (cb) cb->ncurr_cconn++;

        STATS_LOCK();
        ncurr_cconn ++;
        STATS_UNLOCK();
    } else {
        /*
         * server receives a response, possibly parsing it, and sends a
         * request upstream.
         */
        conn->recv = msg_recv;
        conn->recv_next = rsp_recv_next;
        conn->recv_done = rsp_recv_done;

        conn->send = msg_send;
        conn->send_next = req_send_next;
        conn->send_done = req_send_done;

        conn->close = server_close;
        conn->active = server_active;

        conn->ref = server_ref;
        conn->unref = server_unref;

        conn->enqueue_inq = req_server_enqueue_imsgq;
        conn->dequeue_inq = req_server_dequeue_imsgq;
        conn->enqueue_outq = req_server_enqueue_omsgq;
        conn->dequeue_outq = req_server_dequeue_omsgq;
        if (source_type == NC_SOURCE_TYPE_REDIS) {
            conn->post_connect = redis_post_connect;
            conn->swallow_msg = redis_swallow_msg;
        } else {
            conn->post_connect = memcache_post_connect;
            conn->swallow_msg = memcache_swallow_msg;
        }
    }

    if (source_type == NC_SOURCE_TYPE_PROXY) {

    }
    conn->ref(conn, owner);
    log_debug(LOG_VVERB, "get conn %p client %d", conn, conn->client);

    return conn;
}
Exemplo n.º 8
0
struct conn *
conn_get(int sd, conn_state_t state, int ev_flags, int rsize, int udp)
{
    struct conn *c;

    ASSERT(state >= CONN_LISTEN && state < CONN_SENTINEL);
    ASSERT(rsize > 0);

    c = _conn_get();
    if (c == NULL) {
        c = mc_zalloc(sizeof(*c));
        if (c == NULL) {
            return NULL;
        }

        c->rsize = rsize;
        c->rbuf = mc_alloc(c->rsize);

        c->wsize = TCP_BUFFER_SIZE;
        c->wbuf = mc_alloc(c->wsize);

        c->isize = ILIST_SIZE;
        c->ilist = mc_alloc(sizeof(*c->ilist) * c->isize);

        c->ssize = SLIST_SIZE;
        c->slist = mc_alloc(sizeof(*c->slist) * c->ssize);

        c->iov_size = IOV_SIZE;
        c->iov = mc_alloc(sizeof(*c->iov) * c->iov_size);

        c->msg_size = MSG_SIZE;
        c->msg = mc_alloc(sizeof(*c->msg) * c->msg_size);

        if (c->rbuf == NULL || c->wbuf == NULL || c->ilist == NULL ||
            c->iov == NULL || c->msg == NULL || c->slist == NULL) {
            conn_free(c);
            return NULL;
        }

        stats_thread_incr(conn_struct);
    }

    STAILQ_NEXT(c, c_tqe) = NULL;
    c->thread = NULL;

    c->sd = sd;
    c->state = state;
    /* c->event is initialized later */
    c->ev_flags = ev_flags;
    c->which = 0;

    ASSERT(c->rbuf != NULL && c->rsize > 0);
    c->rcurr = c->rbuf;
    c->rbytes = 0;

    ASSERT(c->wbuf != NULL && c->wsize > 0);
    c->wcurr = c->wbuf;
    c->wbytes = 0;

    c->write_and_go = state;
    c->write_and_free = NULL;

    c->ritem = NULL;
    c->rlbytes = 0;

    c->item = NULL;
    c->sbytes = 0;

    ASSERT(c->iov != NULL && c->iov_size > 0);
    c->iov_used = 0;

    ASSERT(c->msg != NULL && c->msg_size > 0);
    c->msg_used = 0;
    c->msg_curr = 0;
    c->msg_bytes = 0;

    ASSERT(c->ilist != NULL && c->isize > 0);
    c->icurr = c->ilist;
    c->ileft = 0;

    ASSERT(c->slist != NULL && c->ssize > 0);
    c->scurr = c->slist;
    c->sleft = 0;

    c->stats.buffer = NULL;
    c->stats.size = 0;
    c->stats.offset = 0;

    c->req_type = REQ_UNKNOWN;
    c->req = NULL;
    c->req_len = 0;

    c->udp = udp;
    c->udp_rid = 0;
    c->udp_hbuf = NULL;
    c->udp_hsize = 0;

    c->noreply = 0;

    stats_thread_incr(conn_total);
    stats_thread_incr(conn_curr);

    log_debug(LOG_VVERB, "get conn %p c %d", c, c->sd);

    return c;
}
Exemplo n.º 9
0
struct conn *
conn_get(void *owner, bool client, bool redis)
{
    struct conn *conn;

    conn = _conn_get();
    if (conn == NULL) {
        return NULL;
    }

    /* connection either handles redis or memcache messages */
    conn->redis = redis ? 1 : 0;

    conn->client = client ? 1 : 0;

    if (conn->client) {
        /*
         * client receives a request, possibly parsing it, and sends a
         * response downstream.
         */
        conn->recv = msg_recv;
        conn->recv_next = req_recv_next;
        conn->recv_done = req_recv_done;

        conn->send = msg_send;
        conn->send_next = rsp_send_next;
        conn->send_done = rsp_send_done;

        conn->close = client_close;
        conn->active = client_active;
        conn->restore = client_restore;

        conn->ref = client_ref;
        conn->unref = client_unref;

        conn->enqueue_inq = NULL;
        conn->dequeue_inq = NULL;
        conn->enqueue_outq = req_client_enqueue_omsgq;
        conn->dequeue_outq = req_client_dequeue_omsgq;
    } else {
        /*
         * server receives a response, possibly parsing it, and sends a
         * request upstream.
         */
        conn->recv = msg_recv;
        conn->recv_next = rsp_recv_next;
        conn->recv_done = rsp_recv_done;

        conn->send = msg_send;
        conn->send_next = req_send_next;
        conn->send_done = req_send_done;

        conn->close = server_close;
        conn->active = server_active;
        conn->restore = server_restore;

        conn->ref = server_ref;
        conn->unref = server_unref;

        conn->enqueue_inq = req_server_enqueue_imsgq;
        conn->dequeue_inq = req_server_dequeue_imsgq;
        conn->enqueue_outq = req_server_enqueue_omsgq;
        conn->dequeue_outq = req_server_dequeue_omsgq;
    }

    conn->ref(conn, owner);

    log_debug(LOG_VVERB, "get conn %p client %d", conn, conn->client);

    return conn;
}