Skip to content

Commit

Permalink
dill_iolfrom function added
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Sustrik <[email protected]>
  • Loading branch information
sustrik committed Apr 20, 2018
1 parent 571b229 commit b96b20f
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 10 deletions.
8 changes: 2 additions & 6 deletions dtls.c
Original file line number Diff line number Diff line change
Expand Up @@ -316,12 +316,8 @@ static int dill_dtls_msendl(struct dill_msock_vfs *mvfs,
if(!self->buf) {errno = ENOMEM; return -1;}
self->buflen = sz;
}
uint8_t *ptr = self->buf;
while(first) {
memcpy(ptr, first->iol_base, first->iol_len);
ptr += first->iol_len;
first = first->iol_next;
}
rc = dill_iolfrom(self->buf, self->buflen, first);
dill_assert(rc == 0);
iol.iol_base = self->buf;
iol.iol_len = sz;
}
Expand Down
14 changes: 13 additions & 1 deletion iol.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ int dill_ioltrim(struct iolist *first, size_t n, struct iolist *result) {
return 0;
}

int dill_iolcopy(const void *src, size_t srclen, struct iolist *first) {
int dill_iolto(const void *src, size_t srclen, struct iolist *first) {
const uint8_t *p = src;
while(1) {
if(!srclen) return 0;
Expand All @@ -94,3 +94,15 @@ int dill_iolcopy(const void *src, size_t srclen, struct iolist *first) {
return 0;
}

int dill_iolfrom(void *dst, size_t dstlen, struct dill_iolist *first) {
uint8_t *p = dst;
while(first) {
if(dstlen < first->iol_len) return -1;
memcpy(p, first->iol_base, first->iol_len);
p += first->iol_len;
dstlen -= first->iol_len;
first = first->iol_next;
}
return 0;
}

8 changes: 6 additions & 2 deletions iol.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,13 @@ void dill_ioltoiov(struct dill_iolist *first, struct iovec *iov);
int dill_ioltrim(struct dill_iolist *first, size_t n,
struct dill_iolist *result);

/* Copies supplied bytes into the iolist. Returns 0 on success, -1 is bytes
/* Copies supplied bytes into the iolist. Returns 0 on success, -1 if bytes
won't fit into the iolist. */
int dill_iolcopy(const void *src, size_t srclen, struct dill_iolist *first);
int dill_iolto(const void *src, size_t srclen, struct dill_iolist *first);

/* Copies supplied bytes from the iolist. Returns 0 on success, -1 is bytes
won't fit into the buffer. */
int dill_iolfrom(void *dst, size_t dstlen, struct dill_iolist *first);

#endif

2 changes: 1 addition & 1 deletion term.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ static ssize_t dill_term_mrecvl(struct dill_msock_vfs *mvfs,
errno = EPIPE;
return -1;
}
dill_iolcopy(buf, self->len, first);
dill_iolto(buf, self->len, first);
return sz;
}

Expand Down

0 comments on commit b96b20f

Please sign in to comment.