예제 #1
0
/*
 * tnt_update_splice()
 *
 * write update splice operation to buffer stream;
 *
 * s      - stream buffer pointer
 * field  - field number
 * offset - splice offset
 * length - splice length
 * data   - splice operation data
 * value  - splice operation data size
 * 
 * returns number of bytes written, or -1 on error.
*/
ssize_t
tnt_update_splice(struct tnt_stream *s, uint32_t field,
		  uint32_t offset,
		  int32_t length, char *data, size_t size)
{
	/* calculating splice data sizes */
	uint32_t offset_len = tnt_enc_size(sizeof(offset)),
	         length_len = tnt_enc_size(sizeof(length)),
	         data_len   = tnt_enc_size(size);
	uint32_t sz = offset_len + sizeof(offset) +
		      length_len + sizeof(length) + data_len + size;
	/* allocating splice request buffer */
	char *buf = tnt_mem_alloc(sz);
	if (buf == NULL)
		return -1;
	/* filling splice request data */
	char *p = buf;
	tnt_enc_write(p, sizeof(offset));
	p += offset_len;
	memcpy(p, &offset, sizeof(offset));
	p += sizeof(offset);
	tnt_enc_write(p, sizeof(length));
	p += length_len;
	memcpy(p, &length, sizeof(length));
	p += sizeof(length);
	tnt_enc_write(p, size);
	p += data_len;
	memcpy(p, data, size);
	p += size;
	/* writing splice request */
	ssize_t rc = tnt_update_op(s, field, TNT_UPDATE_SPLICE, buf, sz);
	tnt_mem_free(buf);
	return rc;
}
예제 #2
0
static ssize_t
tnt_update_op(struct tnt_stream *s,
	      uint32_t field, uint8_t op, char *data, uint32_t size) 
{
	/* encoding size */
	int encs = tnt_enc_size(size);
	char enc[5];
	tnt_enc_write(enc, size);
	struct iovec iov[4];
	int iovc = 3;
	/* field */
	iov[0].iov_base = &field;
	iov[0].iov_len = 4;
	/* operation */
	iov[1].iov_base = &op;
	iov[1].iov_len = 1;
	/* encoding size */
	iov[2].iov_base = enc;
	iov[2].iov_len = encs;
	/* data */
	if (data) {
		iov[3].iov_base = data;
		iov[3].iov_len = size;
		iovc++;
	}
	return s->writev(s, iov, iovc);
}
예제 #3
0
파일: tnt_call.c 프로젝트: bigbes/tarantool
/*
 * tnt_call()
 *
 * write call request to stream;
 *
 * s     - stream pointer
 * flags - request flags
 * proc  - remote procedure name
 * args  - call arguments
 * 
 * returns number of bytes written, or -1 on error.
*/
ssize_t
tnt_call(struct tnt_stream *s, uint32_t flags, const char *proc,
	 struct tnt_tuple *args)
{
	/* encoding procedure name */
	int proc_len = strlen(proc);
	int proc_enc_size = tnt_enc_size(proc_len);
	char proc_enc[5];
	tnt_enc_write(proc_enc, proc_len);
	/* filling major header */
	struct tnt_header hdr;
	hdr.type = TNT_OP_CALL;
	hdr.len = sizeof(struct tnt_header_call) +
		  proc_enc_size + proc_len + args->size;
	if (args->size == 0)
		hdr.len += 4;
	hdr.reqid = s->reqid;
	/* filling call header */
	struct tnt_header_call hdr_call;
	hdr_call.flags = flags;
	/* writing data to stream */
	struct iovec v[5];
	v[0].iov_base = (void *)&hdr;
	v[0].iov_len  = sizeof(struct tnt_header);
	v[1].iov_base = (void *)&hdr_call;
	v[1].iov_len  = sizeof(struct tnt_header_call);
	v[2].iov_base = proc_enc;
	v[2].iov_len  = proc_enc_size;
	v[3].iov_base = (void *)proc;
	v[3].iov_len  = proc_len;
	uint32_t argc = 0;
	if (args->size == 0) {
		v[4].iov_base = (void *)&argc;
		v[4].iov_len  = 4;
	} else {
		v[4].iov_base = args->data;
		v[4].iov_len  = args->size;
	}
	return s->writev(s, v, 5);
}