Skip to content

Commit

Permalink
add two functions to the API: readmsg and sizeb
Browse files Browse the repository at this point in the history
  • Loading branch information
fgrisez committed Jun 21, 2015
1 parent 75baaa5 commit 187b688
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
5 changes: 5 additions & 0 deletions include/ortp/str_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ ORTP_PUBLIC mblk_t *dupb(mblk_t *m);
/* duplicates a complex mblk_t, buffer is not duplicated */
ORTP_PUBLIC mblk_t *dupmsg(mblk_t* m);

ORTP_PUBLIC size_t readmsg(mblk_t *m, size_t rsize, uint8_t *data);

/* returns the size of the buffer */
ORTP_PUBLIC size_t sizeb(const mblk_t *buf);

/* returns the size of data of a message */
ORTP_PUBLIC size_t msgdsize(const mblk_t *mp);

Expand Down
30 changes: 30 additions & 0 deletions src/str_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,32 @@ mblk_t *dupmsg(mblk_t* m)
return newm;
}

size_t readmsg(mblk_t *m, size_t rsize, uint8_t *data) {
mblk_t *it;
size_t res = 0;

for(it = m; it != NULL; it = it->b_cont) {
if(it->b_rptr < it->b_wptr) break;
}
if(it == NULL) return 0;

do {
size_t buf_size = sizeb(it), to_read;
if(res + buf_size < rsize) {
to_read = buf_size;
} else {
to_read = rsize - res;
}
memcpy(data, it->b_rptr, to_read);
it->b_rptr += to_read;
data += to_read;
res += to_read;
it = it->b_cont;
} while(it != NULL && res < rsize);

return res;
}

void putq(queue_t *q,mblk_t *mp)
{
q->_q_stopper.b_prev->b_next=mp;
Expand Down Expand Up @@ -228,6 +254,10 @@ void flushq(queue_t *q, int how)
}
}

size_t sizeb(const mblk_t *buf) {
return buf->b_wptr - buf->b_rptr;
}

size_t msgdsize(const mblk_t *mp)
{
size_t msgsize=0;
Expand Down

0 comments on commit 187b688

Please sign in to comment.