/* Do the actual work of forwarding the command from an * upstream ascii conn to its assigned ascii downstream. */ bool cproxy_forward_a2a_downstream(downstream *d) { assert(d != NULL); conn *uc = d->upstream_conn; assert(uc != NULL); assert(uc->state == conn_pause); assert(uc->cmd_start != NULL); assert(uc->thread != NULL); assert(uc->thread->base != NULL); assert(IS_ASCII(uc->protocol)); assert(IS_PROXY(uc->protocol)); if (cproxy_connect_downstream(d, uc->thread) > 0) { assert(d->downstream_conns != NULL); if (uc->cmd == -1) { return cproxy_forward_a2a_simple_downstream(d, uc->cmd_start, uc); } else { return cproxy_forward_a2a_item_downstream(d, uc->cmd, uc->item, uc); } } return false; }
/* Do the actual work of forwarding the command from an * upstream ascii conn to its assigned ascii downstream. */ bool cproxy_forward_a2a_downstream(downstream *d) { assert(d != NULL); conn *uc = d->upstream_conn; assert(uc != NULL); assert(uc->state == conn_pause); assert(uc->cmd_start != NULL); assert(uc->thread != NULL); assert(uc->thread->base != NULL); assert(IS_ASCII(uc->protocol)); assert(IS_PROXY(uc->protocol)); int server_index = -1; if (cproxy_is_broadcast_cmd(uc->cmd_curr) == true) { cproxy_ascii_broadcast_suffix(d); } else { char *key = NULL; int key_len = 0; if (ascii_scan_key(uc->cmd_start, &key, &key_len) && key != NULL && key_len > 0) { server_index = cproxy_server_index(d, key, key_len, NULL); if (server_index < 0) { return false; } } } int nc = cproxy_connect_downstream(d, uc->thread, server_index); if (nc == -1) { return true; } if (nc > 0) { assert(d->downstream_conns != NULL); if (d->usec_start == 0 && d->ptd->behavior_pool.base.time_stats) { d->usec_start = usec_now(); } if (uc->cmd == -1) { return cproxy_forward_a2a_simple_downstream(d, uc->cmd_start, uc); } else { return cproxy_forward_a2a_item_downstream(d, uc->cmd, uc->item, uc); } } if (settings.verbose > 2) { moxi_log_write("%d: cproxy_forward_a2a_downstream connect failed\n", uc->sfd); } return false; }