示例#1
0
static int verify_server(struct connection *server)
{
    if (server->info == NULL) {
        LOG(ERROR, "verify_server: connection info of server %d is null",
                server->fd);
        return CORVUS_ERR;
    }
    struct conn_info *info = server->info;
    if (info->status != DISCONNECTED) {
        return CORVUS_OK;
    }

    if (server->fd != -1) {
        close(server->fd);
    }

    server->fd = conn_create_fd();
    if (server->fd == -1) {
        LOG(ERROR, "verify_server: fail to create fd");
        conn_free(server);
        return CORVUS_ERR;
    }

    if (conn_connect(server) == CORVUS_ERR) {
        LOG(ERROR, "verify_server: fail to connect %s:%d",
                info->addr.ip, info->addr.port);
        conn_free(server);
        return CORVUS_ERR;
    }
    server->registered = false;
    return CORVUS_OK;
}
示例#2
0
static struct connection *conn_create_server(struct context *ctx, struct address *addr, char *key)
{
    int fd = conn_create_fd();
    if (fd == -1) {
        LOG(ERROR, "conn_create_server: fail to create fd");
        return NULL;
    }
    struct connection *server = server_create(ctx, fd);
    struct conn_info *info = server->info;
    memcpy(&info->addr, addr, sizeof(info->addr));

    if (conn_connect(server) == CORVUS_ERR) {
        LOG(ERROR, "conn_create_server: fail to connect %s:%d",
                info->addr.ip, info->addr.port);
        conn_free(server);
        conn_buf_free(server);
        conn_recycle(ctx, server);
        return NULL;
    }

    strncpy(info->dsn, key, DSN_LEN);
    dict_set(&ctx->server_table, info->dsn, (void*)server);
    TAILQ_INSERT_TAIL(&ctx->servers, server, next);
    return server;
}
示例#3
0
static struct connection *conn_create_server(struct context *ctx,
        struct address *addr, char *key, bool readonly)
{
    int fd = conn_create_fd();
    if (fd == -1) {
        LOG(ERROR, "conn_create_server: fail to create fd");
        return NULL;
    }
    struct connection *server = server_create(ctx, fd);
    struct conn_info *info = server->info;
    memcpy(&info->addr, addr, sizeof(info->addr));
    extern const size_t CMD_NUM;
    info->slow_cmd_counts = cv_calloc(CMD_NUM, sizeof(uint32_t));

    if (conn_connect(server) == CORVUS_ERR) {
        LOG(ERROR, "conn_create_server: fail to connect %s:%d",
                info->addr.ip, info->addr.port);
        conn_free(server);
        conn_buf_free(server);
        conn_recycle(ctx, server);
        return NULL;
    }

    if (readonly) {
        server->info->readonly = true;
    }

    strncpy(info->dsn, key, ADDRESS_LEN);
    dict_set(&ctx->server_table, info->dsn, (void*)server);
    TAILQ_INSERT_TAIL(&ctx->servers, server, next);
    return server;
}