⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ss_strm.c

📁 中国石油二期加油站IC系统后台通讯软件
💻 C
📖 第 1 页 / 共 3 页
字号:

    /* link in the passed mblock */
    mp->b_cont = bp;

    RETVOID;
} /* ssLinkB */


/*
*
*       Fun:   ssMsgDSize
*
*       Desc:  Returns the number of bytes of data in the
*              specified message.
*
*       Ret:   S32      - number of bytes
*
*       Notes:
*
*       File:  ss_strm.c
*
*/
#ifdef ANSI
PUBLIC S32 ssMsgDSize
(
SsMblk *mp                      /* message block */
)
#else
PUBLIC S32 ssMsgDSize(mp)
SsMblk *mp;                     /* message block */
#endif
{
    S32 n;                       /* temporary */
    S32 size;                    /* size of data */


    TRC1(ssMsgDSize);


    /* for all blocks that are of type data, count the bytes */
    size = 0;
    while (mp)
    {
        if (mp->b_datap->db_type == SS_M_DATA)
        {
            n = mp->b_wptr - mp->b_rptr;
            if (n > 0)
            {
                size += n;
            }
        }

        mp = mp->b_cont;
    }


    RETVALUE(size);
} /* ssMsgDSize */


/*
*
*       Fun:   ssPullupMsg
*
*       Desc:  Concatenates and aligns the first 'len' bytes
*              of the specified message into a single, contiguous
*              message block.
*
*       Ret:   1        - success
*              0        - failure
*
*       Notes:
*
*       File:  ss_strm.c
*
*/
#ifdef ANSI
PUBLIC S32 ssPullupMsg
(
SsMblk *mp,                     /* message block */
S32 len                         /* number of bytes to align */
)
#else
PUBLIC S32 ssPullupMsg(mp, len)
SsMblk *mp;                     /* message block */
S32 len;                        /* number of bytes to align */
#endif
{
    SsMblk *bp;                  /* mblk for iteration */
    SsMblk *newbp;               /* the new mblk */
    SsMblk *prev;                /* mblk of same type */
    U8 *base;                    /* for swapping data buffers */
    U8 *lim;                     /* for swapping data buffers */
    U8 *rptr;                    /* for swapping data buffers */
    U8 *wptr;                    /* for swapping data buffers */
    SsFrtn *frtn;                /* for swapping data buffers */
    S32 mLen;                    /* number of bytes in all blocks of same type */
    S32 m;                       /* temporary */
    S32 n;                       /* temporary */
    U8 type;                     /* message type */


    TRC1(ssPullupMsg);


#if (ERRCLASS & ERRCLS_INT_PAR)
    if (mp == NULLP)
    {
        SSLOGERROR(ERRCLS_INT_PAR, ESS445, ERRZERO, "Null pointer");
        RETVALUE(0);
    }

    if (len < -1)
    {
        SSLOGERROR(ERRCLS_INT_PAR, ESS446, len, "Invalid length");
        RETVALUE(0);
    }
#endif


    /* count the number of bytes in all blocks of the same type */
    bp = mp;
    mLen = 0;
    type = bp->b_datap->db_type;
    while (bp  &&  bp->b_datap->db_type == type)
    {
        n = bp->b_wptr - bp->b_rptr;
        if (n > 0)
        {
            mLen += n;
        }

        bp = bp->b_cont;
    }

    /* if -1 has been passed, we want to pull up all bytes */
    if (len == -1)
    {
        len = mLen;
    }

    if (len == 0)
    {
        RETVALUE(1);
    }


    /* do we have enough bytes to pull up? */
    if (len < 0  ||  len > mLen)
    {
        RETVALUE(0);
    }


    /* allocate a new message of the required size */
    newbp = ssAllocB(len, 0);
    if (newbp == NULLP)
    {
        RETVALUE(0);
    }

    newbp->b_datap->db_type = mp->b_datap->db_type;


    /*  now we copy all the data in the blocks of the same type into
     *  this new message
     */

    prev = NULLP;
    bp = mp;
    while (bp != NULLP)
    {
        /* if this buffer is of a different type, we just skip over it */
        if (bp->b_datap->db_type != newbp->b_datap->db_type)
        {
            prev = bp;
            bp = bp->b_cont;
            continue;
        }


        /* we have to copy this buffer */
        n = bp->b_wptr - bp->b_rptr;
        if (n > 0)
        {
            n = m = MIN(n, len);
            while (m > 0)
            {
                *newbp->b_wptr++ = *bp->b_rptr++;
                m--;
            }

            len -= n;
        }


        /*  the buffer is copied, now--can we free it? if this the
         *  first buffer, we don't free it. also, if this buffer has
         *  something in it, we don't free it. otherwise, we link
         *  around this buffer, from the previous one to the next,
         *  and free this buffer.
         */

        if (prev != NULLP  &&  bp->b_rptr == bp->b_wptr)
        {
            prev->b_cont = bp->b_cont;
            bp->b_cont = NULLP;
            ssFreeB(bp);
            bp = prev->b_cont;
        } else
        {
            prev = bp;
        }
    }


    /*  now we have to make the passed mblock point at the new data
     *  buffer we've just filled. then, we have to free the new
     *  mblock we created. also, we have to free the data buffer of
     *  the old mblock, we left it in there. we do this by basically
     *  swapping the data buffers of the passed mblock and the new
     *  mblock, and then freeing the new mblock.
     */

    rptr = mp->b_rptr;
    wptr = mp->b_wptr;
    base = mp->b_datap->db_base;
    lim = mp->b_datap->db_lim;
    frtn = mp->b_datap->db_frtnp;

    mp->b_rptr = newbp->b_rptr;
    mp->b_wptr = newbp->b_wptr;
    mp->b_datap->db_base = newbp->b_datap->db_base;
    mp->b_datap->db_lim = newbp->b_datap->db_lim;
    mp->b_datap->db_frtnp = NULLP;

    newbp->b_rptr = rptr;
    newbp->b_wptr = wptr;
    newbp->b_datap->db_base = base;
    newbp->b_datap->db_lim = lim;
    newbp->b_datap->db_frtnp = frtn;

    ssFreeB(newbp);


    RETVALUE(1);
} /* ssPullupMsg */


/*
*
*       Fun:   ssRmvB
*
*       Desc:  Removes the specified message block from the
*              specified message and restores the linkage of
*              the remaining blocks in the message.
*
*       Ret:   non-NULL - pointer to the head of the new message
*              -1       - specified message block not found in message
*              NULL     - failure
*
*       Notes: The block removed is not freed.
*
*       File:  ss_strm.c
*
*/
#ifdef ANSI
PUBLIC SsMblk *ssRmvB
(
SsMblk *mp,                     /* message */
SsMblk *bp                      /* message block */
)
#else
PUBLIC SsMblk *ssRmvB(mp, bp)
SsMblk *mp;                     /* message */
SsMblk *bp;                     /* message block */
#endif
{
    SsMblk *rp;                  /* mblk that will be returned */


    TRC1(ssRmvB);


#if (ERRCLASS & ERRCLS_INT_PAR)
    if (mp == NULLP  ||  bp == NULLP)
    {
        SSLOGERROR(ERRCLS_INT_PAR, ESS447, ERRZERO, "Null pointer");
        RETVALUE(NULLP);
    }
#endif


    /* we will return rp */
    rp = mp;


    /* if the block to be removed is the first one, its easy */
    if (mp == bp)
    {
        rp = mp->b_cont;
    }
    /* otherwise we run through the message, hunting */
    else
    {
        for (; ;)
        {
            if (mp == NULLP)
            {
                RETVALUE((SsMblk *)-1);
            } else if (mp->b_cont == bp)
            {
                mp->b_cont = bp->b_cont;
                break;
            } else
            {
                mp = mp->b_cont;
            }
        }
    }


    /* we've removed bp from the message, clear its next pointer */
    bp->b_cont = NULLP;


    RETVALUE(rp);
} /* ssRmvB */


/*
*
*       Fun:   ssTestB
*
*       Desc:  Checks for the availability of a message buffer
*              of the specified size without actually retrieving
*              the buffer.
*
*       Ret:   1        - buffer is available
*              0        - not available
*
*       Notes: Is currently a hack that allocates a message and
*              frees it.
*
*       File:  ss_strm.c
*
*/
#ifdef ANSI
PUBLIC S32 ssTestB
(
S32 size,                       /* size required */
U32 pri                         /* priority of the message buffer */
)
#else
PUBLIC S32 ssTestB(size, pri)
S32 size;                       /* size required */
U32 pri;                        /* priority of the message buffer */
#endif
{
    SsMblk *bp;                  /* mblk for iteration */


    TRC1(ssTestB);


    bp = ssAllocB(size, pri);
    if (bp)
    {
        ssFreeB(bp);
        RETVALUE(1);
    }


    RETVALUE(0);
} /* ssTestB */


/*
*
*       Fun:   ssUnlinkB
*
*       Desc:  Removes the first message block pointed at
*              by the specified message and returns a pointer
*              to the head of the resultant message.
*
*       Ret:   non-NULL - head of the new message
*              NULL     - failure
*
*       Notes:
*
*       File:  ss_strm.c
*
*/
#ifdef ANSI
PUBLIC SsMblk *ssUnlinkB
(
SsMblk *mp                      /* message */
)
#else
PUBLIC SsMblk *ssUnlinkB(mp)
SsMblk *mp;                     /* message */
#endif
{
    SsMblk *bp;                  /* mblk for iteration */


    TRC1(ssUnlinkB);


#if (ERRCLASS & ERRCLS_INT_PAR)
    if (mp == NULLP)
    {
        SSLOGERROR(ERRCLS_INT_PAR, ESS448, ERRZERO, "Null pointer");
        RETVALUE(NULLP);
    }
#endif


    /* does this need a comment? ;) */
    bp = mp->b_cont;
    mp->b_cont = NULLP;


    RETVALUE(bp);
} /* ssUnlinkB */




/********************************************************************30**
 
         End of file: ss_strm.c 1.3  -  10/14/98 14:21:37
 
*********************************************************************31*/


/********************************************************************40**
 
        Notes:
 
*********************************************************************41*/

/********************************************************************50**
 
*********************************************************************51*/


/********************************************************************60**
 
        Revision history:
 
*********************************************************************61*/

/********************************************************************70**
 
  version    initials                   description
-----------  ---------  ------------------------------------------------

 
*********************************************************************71*/

/********************************************************************90**
 
     ver       pat    init                  description
------------ -------- ---- ----------------------------------------------
1.1          ---      kp   1. initial release
  
1.2          ---      bsr  1. Regenerated the error codes

1.3          ---      kp   1. Regenerated error codes
*********************************************************************91*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -