Skip to content
Snippets Groups Projects
Commit 0ae52281 authored by Dmitry Simonenko's avatar Dmitry Simonenko
Browse files

connect-c-lite: opsplice implementation.

parent aa2e0fb6
No related branches found
No related tags found
No related merge requests found
......@@ -62,7 +62,7 @@ typedef char *(*tp_resizer)(struct tp *p, size_t req, size_t *size);
#define TP_FREP 4
#define TP_FQUIET 8
#define TP_OPEQ 0
#define TP_OPSET 0
#define TP_OPADD 1
#define TP_OPAND 2
#define TP_OPXOR 3
......@@ -384,7 +384,8 @@ tp_op(struct tp *p, uint32_t field, uint8_t op, char *data,
p->p += sizeof(uint8_t);
/* data */
tp_leb128save(p, size);
memcpy(p->p, data, size);
if (tp_likely(data))
memcpy(p->p, data, size);
p->p += size;
/* update offset and count */
p->h->len += sz;
......@@ -392,6 +393,29 @@ tp_op(struct tp *p, uint32_t field, uint8_t op, char *data,
return tp_used(p);
}
static inline ssize_t
tp_opsplice(struct tp *p, uint32_t field, uint32_t off,
uint32_t len, char *data, size_t size) {
uint32_t olen = tp_leb128sizeof(sizeof(off)),
llen = tp_leb128sizeof(sizeof(len)),
dlen = tp_leb128sizeof(size);
uint32_t sz = olen + sizeof(off) + llen + sizeof(len) +
dlen + size;
ssize_t rc = tp_op(p, field, TP_OPSPLICE, NULL, sz);
if (tp_unlikely(rc == -1))
return -1;
tp_leb128save(p, sizeof(off));
memcpy(p->p, &off, sizeof(off));
p->p += sizeof(off);
tp_leb128save(p, sizeof(len));
memcpy(p->p, &len, sizeof(len));
p->p += sizeof(len);
tp_leb128save(p, size);
memcpy(p->p, data, size);
p += size;
return rc;
}
static inline ssize_t
tp_sz(struct tp *p, char *sz) {
return tp_field(p, sz, strlen(sz));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment