?? ss_strm.c
字號:
/* copy the first mblock */
first = bp = ssCopyB(mp);
if (bp == NULLP)
{
#if (ERRCLASS & ERRCLS_ADD_RES)
SSLOGERROR(ERRCLS_ADD_RES, ESS434, ERRZERO, "ssCopyB() failed");
#endif
RETVALUE(NULLP);
}
/* copy all the rest, linking the new ones at the same time */
while (mp->b_cont)
{
mp = mp->b_cont;
bp->b_cont = ssCopyB(mp);
/* if any copy fails, free whatever exists of the new message */
if (bp->b_cont == NULLP)
{
#if (ERRCLASS & ERRCLS_ADD_RES)
SSLOGERROR(ERRCLS_ADD_RES, ESS435, ERRZERO, "ssCopyB() failed");
#endif
ssFreeMsg(first);
RETVALUE(NULLP);
}
bp = bp->b_cont;
}
RETVALUE(first);
} /* ssCopyMsg */
/*
*
* Fun: ssDupB
*
* Desc: Duplicates the specified message block, copying it
* into a newly-allocated message block. Increments
* the reference count of the data block that is pointed
* at by the original message block descriptor.
*
* Ret: non-NULL - ok
* NULL - failure
*
* Notes:
*
* File: ss_strm.c
*
*/
#ifdef ANSI
PUBLIC SsMblk *ssDupB
(
SsMblk *mp /* message block */
)
#else
PUBLIC SsMblk *ssDupB(mp)
SsMblk *mp; /* message block */
#endif
{
S16 i; /* temporary */
SsMblk *bp; /* mblk for iteration */
TRC1(ssDupB);
#if (ERRCLASS & ERRCLS_INT_PAR)
if (mp == NULLP)
{
SSLOGERROR(ERRCLS_INT_PAR, ESS436, ERRZERO, "Null pointer");
RETVALUE(NULLP);
}
#endif
/* allocate a message with no data buffer */
bp = ssAllocB(0, 0);
if (bp == NULLP)
{
#if (ERRCLASS & ERRCLS_ADD_RES)
SSLOGERROR(ERRCLS_ADD_RES, ESS437, ERRZERO, "ssAllocB() failed");
#endif
RETVALUE(NULLP);
}
/* make the new message block identical to the one to be dup'ed.
* notice that an mblk/dblk pair is allocated but only the mblk
* is used,, this is for optimum performance in the average case.
*/
for (i = 0; i < (S16) sizeof(SsMblk); i++)
{
*(((U8 *) bp) + i) = *(((U8 *) mp) + i);
}
/* increment the reference count of the dblock */
ssLockTsk();
mp->b_datap->db_ref++;
ssUnlockTsk();
RETVALUE(bp);
} /* ssDupB */
/*
*
* Fun: ssDupMsg
*
* Desc: Calls ssDupB to duplicate the specified message by
* copying all message block descriptors and then linking
* the new message blocks together to form a new message.
*
* Ret: non-NULL - ok
* NULL - failure
*
* Notes:
*
* File: ss_strm.c
*
*/
#ifdef ANSI
PUBLIC SsMblk *ssDupMsg
(
SsMblk *mp /* message block */
)
#else
PUBLIC SsMblk *ssDupMsg(mp)
SsMblk *mp; /* message block */
#endif
{
SsMblk *first; /* first mblk in message */
SsMblk *bp; /* mblk for iteration */
TRC1(ssDupMsg);
/* dup the first mblock */
first = bp = ssDupB(mp);
if (bp == NULLP)
{
#if (ERRCLASS & ERRCLS_ADD_RES)
SSLOGERROR(ERRCLS_ADD_RES, ESS438, ERRZERO, "ssDupB() failed");
#endif
RETVALUE(NULLP);
}
/* dup all the rest, linking the new ones at the same time */
while (mp->b_cont)
{
mp = mp->b_cont;
bp->b_cont = ssDupB(mp);
/* if any dup fails, free whatever exists of the new message */
if (bp->b_cont == NULLP)
{
#if (ERRCLASS & ERRCLS_ADD_RES)
SSLOGERROR(ERRCLS_ADD_RES, ESS439, ERRZERO, "ssDupB() failed");
#endif
ssFreeMsg(first);
RETVALUE(NULLP);
}
bp = bp->b_cont;
}
RETVALUE(first);
} /* ssDupMsg */
/*
*
* Fun: ssESBAlloc
*
* Desc: Allocates message and data blocks that point directly
* at a client-supplied buffer.
*
* Ret: non-NULL - ok
* NULL - failure
*
* Notes:
*
* File: ss_strm.c
*
*/
#ifdef ANSI
PUBLIC SsMblk *ssESBAlloc
(
U8 *base, /* client supplied data buffer */
S32 size, /* size of data buffer */
S32 pri, /* message priority */
SsFrtn *fr_rtn /* free routine */
)
#else
PUBLIC SsMblk *ssESBAlloc(base, size, pri, fr_rtn)
U8 *base; /* client supplied data buffer */
S32 size; /* size of data buffer */
S32 pri; /* message priority */
SsFrtn *fr_rtn; /* free routine */
#endif
{
SsMblk *bp; /* mblk for iteration */
Size m; /* mblk + dblk */
S16 r; /* return value */
TRC1(ssESBAlloc);
UNUSED(pri);
#if (ERRCLASS & ERRCLS_INT_PAR)
if (base == NULLP || fr_rtn == NULLP)
{
SSLOGERROR(ERRCLS_INT_PAR, ESS440, ERRZERO, "Null pointer");
RETVALUE(NULLP);
}
#endif
/* allocate space for an mblock and a dblock */
m = (sizeof(SsMblk) + sizeof(SsDblk));
r = SAlloc(strmCfg.mdRegion, &m, 0, (Data **)&bp);
if (r != ROK)
{
#if (ERRCLASS & ERRCLS_ADD_RES)
SSLOGERROR(ERRCLS_ADD_RES, ESS441, (ErrVal) r, "SAlloc() failed");
#endif
RETVALUE(NULLP);
}
/* use the generic set-up-message function to initialize everything */
SS_STRM_INITB(bp, (SsDblk *)(((U8 *)bp) + sizeof(SsMblk)),
base, size, fr_rtn);
RETVALUE(bp);
} /* ssESBAlloc */
/*
*
* Fun: ssFreeB
*
* Desc: Deallocates the specified message block descriptor
* and frees the corresponding data block if the
* reference count is equal to 1. If not, the reference
* count is decremented.
*
* Ret: Void
*
* Notes:
*
* File: ss_strm.c
*
*/
#ifdef ANSI
PUBLIC Void ssFreeB
(
SsMblk *mp /* message block */
)
#else
PUBLIC Void ssFreeB(mp)
SsMblk *mp; /* message block */
#endif
{
SsMblk *bp; /* mblk for iteration */
Size size; /* mblk + dblk */
TRC1(ssFreeB);
#if (ERRCLASS & ERRCLS_INT_PAR)
if (mp == NULLP)
{
SSLOGERROR(ERRCLS_INT_PAR, ESS442, ERRZERO, "Null pointer");
RETVOID;
}
#endif
size = sizeof(SsMblk) + sizeof(SsDblk);
/* this mblock has already been freed, and still exists only
* because there is a reference to its dblock. it will be
* freed when the referring mblock is freed.
*/
if (mp->b_datap == NULLP)
{
RETVOID;
}
/* ?? this should never happen ?? */
ssLockTsk();
if (mp->b_datap->db_ref == 0)
{
ssUnlockTsk();
#if (ERRCLASS & ERRCLS_DEBUG)
SSLOGERROR(ERRCLS_DEBUG, ESS443, ERRZERO,
"Zero reference count in ssFreeB; logic failure");
#endif
SFree(strmCfg.mdRegion, (Data *)mp, size);
RETVOID;
}
/* decrement reference count of the dblock */
mp->b_datap->db_ref--;
/* if we have no more references to this dblock, we can free
* the data buffer and the header.
*/
if (mp->b_datap->db_ref == 0)
{
ssUnlockTsk();
/* if there is a free routine, we call it for the data buffer;
* otherwise, we've allocated the data buffer and so we free it.
*/
if (mp->b_datap->db_frtnp)
{
(*(mp->b_datap->db_frtnp->free_func))(mp->b_datap->db_frtnp->free_arg);
} else if (mp->b_datap->db_base != NULLP)
{
SFree(strmCfg.datRegion, mp->b_datap->db_base,
(Size)(mp->b_datap->db_lim - mp->b_datap->db_base));
}
/* if the dblock is in this header, we free this header
* and we're done. if the dblock is in another header,
* we have to free that header too.
*/
if (mp->b_datap != ((SsDblk *)(mp + sizeof(SsMblk))))
{
bp = (SsMblk *)(mp->b_datap - sizeof (SsMblk));
SFree(strmCfg.mdRegion, (Data *)bp, size);
}
SFree(strmCfg.mdRegion, (Data *)mp, size);
} else
{
ssUnlockTsk();
/* reference count is non-zero; if it is this header's
* dblock, we don't free the header, we just mark the
* dblock pointer empty so we know about it. if it is
* another header's dblock, we can free this header.
*/
if (mp->b_datap == (SsDblk *)(mp + sizeof(SsMblk)))
{
mp->b_datap = NULLP;
} else
{
SFree(strmCfg.mdRegion, (Data *)mp, size);
}
}
RETVOID;
} /* ssFreeB */
/*
*
* Fun: ssFreeMsg
*
* Desc: Calls ssFreeB to free all message blocks and their
* corresponding data blocks for the specified
* message.
*
* Ret: Void
*
* Notes:
*
* File: ss_strm.c
*
*/
#ifdef ANSI
PUBLIC Void ssFreeMsg
(
SsMblk *mp /* message block */
)
#else
PUBLIC Void ssFreeMsg(mp)
SsMblk *mp; /* message block */
#endif
{
SsMblk *bp; /* mblk for iteration */
TRC1(ssFreeMsg);
/* free all the message blocks in the message */
while (mp)
{
bp = mp;
mp = mp->b_cont;
ssFreeB(bp);
}
RETVOID;
} /* ssFreeMsg */
/*
*
* Fun: ssLinkB
*
* Desc: Puts the second specified message at the tail of
* the first specified message.
*
* Ret: Void
*
* Notes:
*
* File: ss_strm.c
*
*/
#ifdef ANSI
PUBLIC Void ssLinkB
(
SsMblk *mp, /* first message block */
SsMblk *bp /* second message block */
)
#else
PUBLIC Void ssLinkB(mp, bp)
SsMblk *mp; /* first message block */
SsMblk *bp; /* second message block */
#endif
{
TRC1(ssLinkB);
#if (ERRCLASS & ERRCLS_INT_PAR)
if (mp == NULLP || bp == NULLP)
{
SSLOGERROR(ERRCLS_INT_PAR, ESS444, ERRZERO, "Null pointer");
RETVOID;
}
#endif
/* run down to the end of the message */
while (mp->b_cont)
{
mp = mp->b_cont;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -