예제 #1
0
void
recv_command(char *command)
{
	struct tnt_iter i;
	tnt_iter_reply(&i, tnt);
	while (tnt_next(&i)) {
		struct tnt_reply *r = TNT_IREPLY_PTR(&i);
		printf("%s: respond %s (op: %"PRIu32", reqid: %"PRIu32", code: %"PRIu32", count: %"PRIu32")\n",
			command, tnt_strerror(tnt),
			r->op,
			r->reqid,
			r->code,
			r->count);
		struct tnt_iter it;
		tnt_iter_list(&it, TNT_REPLY_LIST(r));
		while (tnt_next(&it)) {
			struct tnt_tuple *tu = TNT_ILIST_TUPLE(&it);
			print_tuple(tu);
		}
		tnt_iter_free(&it);
	}
	if (i.status == TNT_ITER_FAIL)
		fail_tnt_perror("tnt_next");
	tnt_iter_free(&i);
}
예제 #2
0
파일: tc.c 프로젝트: cbin/tarantool
static void tc_connect(void)
{
	/* allocating stream */
	tc.net = tnt_net(NULL);
	if (tc.net == NULL)
		tc_error("stream allocation error");
	/* initializing network stream */
	tnt_set(tc.net, TNT_OPT_HOSTNAME, tc.opt.host);
	tnt_set(tc.net, TNT_OPT_PORT, tc.opt.port);
	tnt_set(tc.net, TNT_OPT_SEND_BUF, 0);
	tnt_set(tc.net, TNT_OPT_RECV_BUF, 0);
	if (tnt_init(tc.net) == -1)
		tc_error("%s", tnt_strerror(tc.net));
	/* connecting to server */
	if (tnt_connect(tc.net) == -1)
		tc_error("%s", tnt_strerror(tc.net));
}
예제 #3
0
int tc_query(char *q, char **e) {
    int rc = tnt_query(tc.net, q, strlen(q), e);
    if (rc == -1)
        return -1;
    rc = tnt_flush(tc.net);
    if (rc < 0) {
        char *ee = tnt_strerror(tc.net);
        if (ee) {
            *e = tc_query_error("%s", ee);
        }
        return -1;
    }
    return 0;
}
예제 #4
0
int tc_query_foreach(tc_query_t cb, void *cba, char **e)
{
    int rc = -1;
    struct tnt_iter i;
    tnt_iter_reply(&i, tc.net);
    while (tnt_next(&i)) {
        struct tnt_reply *r = TNT_IREPLY_PTR(&i);
        if (tnt_error(tc.net) != TNT_EOK) {
            *e = tc_query_error("%s ERROR, %s",
                                tc_query_op(r),
                                tnt_strerror(tc.net));
            goto error;
        } else if (r->code != 0) {
            *e = tc_query_error("%s ERROR, %s (%s)",
                                tc_query_op(r), ((r->error) ? r->error : ""),
                                tnt_errcode_str(r->code >> 8));
            goto error;
        }
        /* invoking callback if supplied */
        if (cb) {
            if (cb(r, cba, e) == -1)
                goto error;
        }
    }
예제 #5
0
void
fail_tnt_perror(char *msg)
{
	printf("fail: %s: %s\n", msg, tnt_strerror(tnt));
	exit(EXIT_FAILURE);
}