struct conn * server_pool_conn(struct context *ctx, struct server_pool *pool, uint8_t *key, uint32_t keylen) { rstatus_t status; struct server *server; struct conn *conn; status = server_pool_update(pool); if (status != DN_OK) { return NULL; } /* from a given {key, keylen} pick a server from pool */ server = server_pool_server(pool, key, keylen); if (server == NULL) { return NULL; } /* pick a connection to a given server */ conn = server_conn(server); if (conn == NULL) { return NULL; } status = server_connect(ctx, server, conn); if (status != DN_OK) { server_close(ctx, conn); return NULL; } return conn; }
struct conn * server_pool_conn(struct context *ctx, struct server_pool *pool, uint8_t *key, uint32_t keylen) { rstatus_t status; struct server *server; struct conn *conn; status = server_pool_update(pool); if (status != NC_OK) { return NULL; } /* from a given {key, keylen} pick a server from pool */ server = server_pool_server(pool, key, keylen); if (server == NULL) { return NULL; } /* pick a connection to a given server */ conn = server_conn(server); if (conn == NULL) { return NULL; } //log_error("tyson tyson tyson: %p", TAILQ_FIRST(&server->s_conn_q)); status = server_connect(ctx, server, conn); if (status != NC_OK) { server_close(ctx, conn); return NULL; } return conn; }
static rstatus_t server_each_preconnect(void *elem, void *data) { rstatus_t status; struct server *server; struct server_pool *pool; struct conn *conn; server = elem; pool = server->owner; conn = server_conn(server); if (conn == NULL) { return DN_ENOMEM; } status = server_connect(pool->ctx, server, conn); if (status != DN_OK) { log_warn("connect to server '%.*s' failed, ignored: %s", server->pname.len, server->pname.data, strerror(errno)); server_close(pool->ctx, conn); } return DN_OK; }
rstatus_t ffi_server_connect(struct server *server) { struct server_pool *pool; struct conn *conn; rstatus_t status; pool = server->owner; conn = server_conn(server); if (conn == NULL) { return NC_ERROR; } status = server_connect(pool->ctx, server, conn); if (status != NC_OK) { log_warn("script: connect to server '%.*s' failed, ignored: %s", server->pname.len, server->pname.data, strerror(errno)); server_close(pool->ctx, conn); return NC_ERROR; } return NC_OK; }