/* * tnt_select() * * write select request to stream; * * s - stream pointer * ns - space * index - request index * offset- request offset * limit - request limit * keys - list of tuples keys * * returns number of bytes written, or -1 on error. */ ssize_t tnt_select(struct tnt_stream *s, uint32_t ns, uint32_t index, uint32_t offset, uint32_t limit, struct tnt_list *keys) { /* calculating tuples sizes */ size_t size = 0; struct tnt_iter i; tnt_iter_list(&i, keys); while (tnt_next(&i)) { struct tnt_tuple *t = TNT_ILIST_TUPLE(&i); size += t->size; } /* filling major header */ struct tnt_header hdr; hdr.type = TNT_OP_SELECT; hdr.len = sizeof(struct tnt_header_select) + 4 + size; hdr.reqid = s->reqid; /* filling select header */ struct tnt_header_select hdr_sel; hdr_sel.ns = ns; hdr_sel.index = index; hdr_sel.offset = offset; hdr_sel.limit = limit; /* allocating write vector */ int vc = 3 + keys->count; struct iovec *v = tnt_mem_alloc(sizeof(struct iovec) * vc); if (v == NULL) { tnt_iter_free(&i); return -1; } /* filling write vector */ v[0].iov_base = &hdr; v[0].iov_len = sizeof(struct tnt_header); v[1].iov_base = &hdr_sel; v[1].iov_len = sizeof(struct tnt_header_select); v[2].iov_base = &keys->count; v[2].iov_len = 4; int vi = 3; tnt_rewind(&i); while (tnt_next(&i)) { struct tnt_tuple *t = TNT_ILIST_TUPLE(&i); v[vi].iov_base = t->data; v[vi].iov_len = t->size; vi++; } tnt_iter_free(&i); /* writing data to stream */ ssize_t rc = s->writev(s, v, vc); tnt_mem_free(v); return rc; }
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); }
void tc_print_list(struct tnt_list *l) { struct tnt_iter it; tnt_iter_list(&it, l); while (tnt_next(&it)) { struct tnt_tuple *tu = TNT_ILIST_TUPLE(&it); tc_print_tuple(tu); } tnt_iter_free(&it); }