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; }
void buf_time_append(struct context *ctx, struct buf_time_tqh *queue, struct mbuf *buf, int64_t read_time) { struct buf_time *t; if (!STAILQ_EMPTY(&ctx->free_buf_timeq)) { t = STAILQ_FIRST(&ctx->free_buf_timeq); STAILQ_REMOVE_HEAD(&ctx->free_buf_timeq, next); ctx->mstats.free_buf_times--; } else { t = cv_calloc(1, sizeof(struct buf_time)); } t->ctx = ctx; t->buf = buf; t->pos = buf->last; t->read_time = read_time; STAILQ_INSERT_TAIL(queue, t, next); ctx->mstats.buf_times++; }