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; }
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; }