예제 #1
0
ssize_t
tnt_update_assign(struct tnt_stream *ops, uint32_t fieldno,
		  struct tnt_stream *val) {
	if (tnt_object_verify(val, -1))
		return -1;
	return tnt_update_op(ops, '=', fieldno, TNT_SBUF_DATA(val),
			     TNT_SBUF_SIZE(val));
}
예제 #2
0
ssize_t
tnt_update(struct tnt_stream *s, uint32_t space, uint32_t index,
	   struct tnt_stream *key, struct tnt_stream *ops)
{
	if (tnt_object_verify(key, MP_ARRAY))
		return -1;
	if (tnt_object_verify(ops, MP_ARRAY))
		return -1;
	struct tnt_iheader hdr;
	struct iovec v[6]; int v_sz = 6;
	char *data = NULL, *body_start = NULL;
	encode_header(&hdr, TNT_OP_UPDATE, s->reqid++);
	v[1].iov_base = (void *)hdr.header;
	v[1].iov_len  = hdr.end - hdr.header;
	char body[64]; body_start = body; data = body;

	data = mp_encode_map(data, 4);
	data = mp_encode_uint(data, TNT_SPACE);
	data = mp_encode_uint(data, space);
	data = mp_encode_uint(data, TNT_INDEX);
	data = mp_encode_uint(data, index);
	data = mp_encode_uint(data, TNT_KEY);
	v[2].iov_base = (void *)body_start;
	v[2].iov_len  = data - body_start;
	body_start = data;
	v[3].iov_base = TNT_SBUF_DATA(key);
	v[3].iov_len  = TNT_SBUF_SIZE(key);
	data = mp_encode_uint(data, TNT_TUPLE);
	v[4].iov_base = (void *)body_start;
	v[4].iov_len  = data - body_start;
	body_start = data;
	v[5].iov_base = TNT_SBUF_DATA(ops);
	v[5].iov_len  = TNT_SBUF_SIZE(ops);

	size_t package_len = 0;
	for (int i = 1; i < v_sz; ++i)
		package_len += v[i].iov_len;
	char len_prefix[9];
	char *len_end = mp_encode_luint32(len_prefix, package_len);
	v[0].iov_base = len_prefix;
	v[0].iov_len = len_end - len_prefix;
	return s->writev(s, v, v_sz);
}
예제 #3
0
static ssize_t
tnt_rpc_base(struct tnt_stream *s, const char *proc, size_t proc_len,
	     struct tnt_stream *args, enum tnt_request_t op)
{
	if (!proc || proc_len == 0)
		return -1;
	if (tnt_object_verify(args, MP_ARRAY))
		return -1;
	uint32_t fld = (is_call(op) ? TNT_FUNCTION : TNT_EXPRESSION);
	struct tnt_iheader hdr;
	struct iovec v[6]; int v_sz = 6;
	char *data = NULL, *body_start = NULL;
	encode_header(&hdr, op, s->reqid++);
	v[1].iov_base = (void *)hdr.header;
	v[1].iov_len  = hdr.end - hdr.header;
	char body[64]; body_start = body; data = body;

	data = mp_encode_map(data, 2);
	data = mp_encode_uint(data, fld);
	data = mp_encode_strl(data, proc_len);
	v[2].iov_base = body_start;
	v[2].iov_len  = data - body_start;
	v[3].iov_base = (void *)proc;
	v[3].iov_len  = proc_len;
	body_start = data;
	data = mp_encode_uint(data, TNT_TUPLE);
	v[4].iov_base = body_start;
	v[4].iov_len  = data - body_start;
	v[5].iov_base = TNT_SBUF_DATA(args);
	v[5].iov_len  = TNT_SBUF_SIZE(args);

	size_t package_len = 0;
	for (int i = 1; i < v_sz; ++i)
		package_len += v[i].iov_len;
	char len_prefix[9];
	char *len_end = mp_encode_luint32(len_prefix, package_len);
	v[0].iov_base = len_prefix;
	v[0].iov_len = len_end - len_prefix;
	return s->writev(s, v, v_sz);
}