Exemplo n.º 1
0
struct connection *conn_get_server(struct context *ctx, uint16_t slot)
{
    struct address addr;
    struct connection *server = NULL;

    server = slot_get_node_addr(slot, &addr) ?
        conn_get_server_from_pool(ctx, &addr) :
        conn_get_raw_server(ctx);
    return server;
}
Exemplo n.º 2
0
struct connection *conn_get_server(struct context *ctx, uint16_t slot,
        int access)
{
    struct address *addr;
    struct node_info info;
    bool readonly = false;

    if (slot_get_node_addr(slot, &info)) {
        addr = &info.nodes[0];
        if (access != CMD_ACCESS_WRITE && config.readslave && info.index > 1) {
            int r = rand_r(&ctx->seed);
            if (!config.readmasterslave || r % info.index != 0) {
                int i = r % (info.index - 1);
                addr = &info.nodes[++i];
                readonly = true;
            }
        }
        if (addr->port > 0) {
            return conn_get_server_from_pool(ctx, addr, readonly);
        }
    }
    return conn_get_raw_server(ctx);
}