Commit 3320ef89 authored by Simon Morlat's avatar Simon Morlat

add msgown(), a function to know whether the underlying buffer is shared or...

add msgown(), a function to know whether the underlying buffer is shared or not. Not used by anyone at this time.
parent ca1467f2
......@@ -147,6 +147,10 @@ ORTP_PUBLIC void msgappend(mblk_t *mp, const char *data, size_t size, bool_t pad
ORTP_PUBLIC mblk_t *concatb(mblk_t *mp, mblk_t *newm);
/*Make sure the message has a unique owner, if not duplicate the underlying data buffer so that it can be changed without impacting others.
Note that in case of copy, the message will be un-fragmented, exactly the way msgpullup() does. Always returns mp.*/
ORTP_PUBLIC mblk_t * msgown(mblk_t *mp);
#define qempty(q) (&(q)->_q_stopper==(q)->_q_stopper.b_next)
#define qfirst(q) ((q)->_q_stopper.b_next!=&(q)->_q_stopper ? (q)->_q_stopper.b_next : NULL)
#define qbegin(q) ((q)->_q_stopper.b_next)
......@@ -21,6 +21,7 @@
#include "ortp-config.h"
#include "ortp/ortp.h"
#include "ortp/str_utils.h"
#include "utils.h"
......@@ -342,6 +343,9 @@ void msgb_allocator_init(msgb_allocator_t *a){
static void msgb_allocator_free_db(void *unused){
mblk_t *msgb_allocator_alloc(msgb_allocator_t *a, size_t size){
queue_t *q=&a->q;
mblk_t *m,*found=NULL;
......@@ -355,6 +359,8 @@ mblk_t *msgb_allocator_alloc(msgb_allocator_t *a, size_t size){
if (found==NULL){
/*Hack: we put a special freefn impletation to be able to recognize mblk_t allocated by the msgb_allocator_t */
found->b_datap->db_freefn = msgb_allocator_free_db;
return dupb(found);
......@@ -364,6 +370,17 @@ void msgb_allocator_uninit(msgb_allocator_t *a){
/*Same as ownb(), but invoke it for each mblk_t of the chain*/
mblk_t * msgown(mblk_t *mp){
int single_owner_ref = (mp->b_datap->db_freefn == msgb_allocator_free_db) ? 2 : 1;
//ortp_message("msgown(): db_ref=%i single_owner_ref=%i", mp->b_datap->db_ref, single_owner_ref);
if (mp->b_datap->db_ref > single_owner_ref){
msgpullup(mp, msgdsize(mp));
return mp;
void ortp_recvaddr_to_sockaddr(ortp_recv_addr_t *recvaddr, struct sockaddr *addr, socklen_t *socklen) {
if (recvaddr->family == AF_INET) {
struct sockaddr_in *addr_in = (struct sockaddr_in *)addr;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment