📄 ss_msg.c
字号:
*/
#ifdef ANSI
PUBLIC S16 SAddPstMsg
(
Data data,
Buffer *mBuf
)
#else
PUBLIC S16 SAddPstMsg (data, mBuf)
Data data;
Buffer *mBuf;
#endif
{
SsMsgInfo *minfo;
Buffer *tmp;
Buffer *newb;
TRC1(SAddPstMsg)
#if (ERRCLASS & ERRCLS_INT_PAR)
/* check message buffer */
if (!mBuf)
{
SSLOGERROR(ERRCLS_INT_PAR, ESS230, ERRZERO, "SAddPstMsg: Null Buffer");
RETVALUE(RFAILED);
}
if (mBuf->b_datap->db_type != SS_M_PROTO)
{
SSLOGERROR(ERRCLS_INT_PAR, ESS231, ERRZERO, "SAddPstMsg: Incorrect\
buffer type");
RETVALUE(RFAILED);
}
#endif
/* get the message info */
minfo = (SsMsgInfo *) mBuf->b_rptr;
ssLockTsk();
if (!(tmp = minfo->endptr) || (tmp->b_datap->db_ref > 1) ||
(tmp->b_wptr == tmp->b_datap->db_lim))
{
ssUnlockTsk();
if (SGetDBuf(minfo->region, minfo->pool, &newb) != ROK)
{
SSLOGERROR(ERRCLS_DEBUG, ESS232, ERRZERO, "SAddPstMsg: Failed in\
SGetDBuf()");
RETVALUE(ROUTRES);
}
/* append newb to the end of the mBuf chain */
if (tmp)
tmp->b_cont = newb;
else
mBuf->b_cont = newb;
/* set the endptr of mBuf to newb */
minfo->endptr = newb;
tmp = newb;
} else
ssUnlockTsk();
/* insert data, increment length */
*tmp->b_wptr++ = data;
minfo->len++;
RETVALUE(ROK);
}
/*
*
* Fun: SAddPreMsgMult
*
* Desc: This function copies consecutive bytes of data to the
* beginning of a message.
*
* Ret: ROK - ok
* RFAILED - failed, general (optional)
* ROUTRES - failed, out of resources (optional)
*
* Notes: if message is empty: data is placed in the message. message
* length is incremented. return is ok.
*
* if message is not empty: data is read by source pointer,
* data is placed in front of all other data in message.
* message length is incremented. return is ok.
*
* the first byte of data pointed to by the source pointer will
* be placed at the front of the message first, the last byte of
* data pointed to by the source pointer will be placed at the
* front of the message last (i.e. it will become the first
* byte of the message).
*
* File: ss_msg.c
*
*/
#ifdef ANSI
PUBLIC S16 SAddPreMsgMult
(
Data *src,
MsgLen cnt,
Buffer *mBuf
)
#else
PUBLIC S16 SAddPreMsgMult(src, cnt, mBuf)
Data *src;
MsgLen cnt;
Buffer *mBuf;
#endif
{
SsMsgInfo *minfo; /* Message info */
Buffer *tmp;
Buffer *curblk;
Buffer *newblk;
Buffer *prevblk;
MsgLen numBytes; /* no. of bytes to be copied */
MsgLen len;
/* modified by shang */
MsgLen offset = 0;
/* modified by shang over */
Data *rptr;
TRC1(SAddPreMsgMult)
#if (ERRCLASS & ERRCLS_INT_PAR)
/* check message buffer */
if (mBuf == NULLP)
{
SSLOGERROR(ERRCLS_INT_PAR, ESS233, ERRZERO, "SAddPreMsgMult:Null Buffer");
RETVALUE(RFAILED);
}
/* check source */
if (src == NULLP)
{
SSLOGERROR(ERRCLS_INT_PAR, ESS234, ERRZERO, "SAddPreMsgMult:Null Buffer");
RETVALUE(RFAILED);
}
/* check count */
if (cnt <= 0)
{
SSLOGERROR(ERRCLS_INT_PAR, ESS235, ERRZERO, "SAddPreMsgMult: Invalid\
count");
RETVALUE(RFAILED);
}
if (mBuf->b_datap->db_type != SS_M_PROTO)
{
SSLOGERROR(ERRCLS_INT_PAR, ESS236, ERRZERO, "SAddPreMsgMult: Incorrect\
buffer type");
RETVALUE(RFAILED);
}
#endif
/* get the SsMsgInfo of mBuf */
minfo = (SsMsgInfo*) mBuf->b_rptr;
/* store cnt in length */
len = cnt;
ssLockTsk();
if ((tmp = mBuf->b_cont) && (tmp->b_datap->db_ref == 1) &&
(tmp->b_datap->db_base < tmp->b_rptr))
{
ssUnlockTsk();
/* store the offset of the read pointer of tmp */
offset = tmp->b_rptr - tmp->b_datap->db_base;
/* determine the number of bytes to copy */
numBytes = MIN(cnt, offset);
/* decrement cnt */
cnt -= numBytes;
/* copy data */
while (numBytes--)
*--tmp->b_rptr = *src++;
if (!cnt)
{
minfo->len += len;
RETVALUE(ROK);
}
} else
ssUnlockTsk();
newblk = prevblk = NULLP;
while (cnt)
{
/* allocate a message blk */
if (SGetDBuf(minfo->region, minfo->pool, &curblk) != ROK)
{
while ((curblk = prevblk))
{
prevblk = prevblk->b_cont;
(Void) SPutDBuf(minfo->region, minfo->pool, curblk);
}
if (tmp)
{
tmp->b_rptr = tmp->b_datap->db_base + offset;
}
RETVALUE(ROUTRES);
}
/* attach curblk in the newblk chain */
if (prevblk)
curblk->b_cont = prevblk; /* stack them up */
else
newblk = curblk;
prevblk = curblk;
/* set the read and write pointers to the end of the data buffer */
/* subsequent prepends have all the buffer to insert data into */
curblk->b_wptr = curblk->b_datap->db_lim;
rptr = curblk->b_datap->db_lim;
/* copy data */
numBytes = MIN(cnt, (rptr - curblk->b_datap->db_base));
/* decrement cnt */
cnt -= numBytes;
while (numBytes--)
*--rptr = *src++;
curblk->b_rptr = rptr;
}
/* attach the newblk chain into mBuf */
newblk -> b_cont = tmp;
mBuf -> b_cont = curblk;
/* update endptr of mBuf */
if (!tmp)
minfo -> endptr = newblk;
/* update length of message */
minfo->len += len;
RETVALUE(ROK);
}
/*
*
* Fun: SAddPstMsgMult
*
* Desc: This function copies consecutive bytes of data to the
* end of a message.
*
* Ret: ROK - ok
* RFAILED - failed, general (optional)
* ROUTRES - failed, out of resources (optional)
*
* Notes: if message is empty: data is placed in the message. message
* length is incremented. return is ok.
*
* if message is not empty: data is read by source pointer,
* data is placed in back of all other data in message.
* message length is incremented. return is ok.
*
* the first byte of data pointed to by the source pointer will
* be placed at the back of the message first, the last byte of
* data pointed to by the source pointer will be placed at the
* back of the message last (i.e. it will become the last
* byte of the message).
*
* File: ss_msg.c
*
*/
#ifdef ANSI
PUBLIC S16 SAddPstMsgMult
(
Data *src,
MsgLen cnt,
Buffer *mBuf
)
#else
PUBLIC S16 SAddPstMsgMult(src, cnt, mBuf)
Data *src;
MsgLen cnt;
Buffer *mBuf;
#endif
{
SsMsgInfo *minfo;
Buffer *tmp;
Buffer *newblk;
Buffer *curblk;
Buffer *prevblk;
MsgLen len;
/* add by shang */
MsgLen offset = 0;
/* add by shang over */
MsgLen numBytes;
Data *wptr;
TRC1(SAddPstMsgMult)
#if (ERRCLASS & ERRCLS_INT_PAR)
/* check message buffer */
if (mBuf == NULLP)
{
SSLOGERROR(ERRCLS_INT_PAR, ESS237, ERRZERO, "SAddPstMsgMult:Null Buffer");
RETVALUE(RFAILED);
}
/* check source */
if (src == NULLP)
{
SSLOGERROR(ERRCLS_INT_PAR, ESS238, ERRZERO, "SAddPstMsgMult:Null Buffer");
RETVALUE(RFAILED);
}
/* check count */
if (cnt <= 0)
{
SSLOGERROR(ERRCLS_INT_PAR, ESS239, ERRZERO, "SAddPstMsgMult:Invalid\
count");
RETVALUE(RFAILED);
}
if (mBuf->b_datap->db_type != SS_M_PROTO)
{
SSLOGERROR(ERRCLS_INT_PAR, ESS240, ERRZERO, "SAddPstMsgMult: Incorrect\
buffer type");
RETVALUE(RFAILED);
}
#endif
/* get the SsMsgInfo of mBuf */
minfo = (SsMsgInfo*) mBuf->b_rptr;
/* store cnt in len */
len = cnt;
ssLockTsk();
if ((tmp = minfo->endptr) && (tmp->b_datap->db_ref == 1) &&
(tmp->b_datap->db_lim > tmp->b_wptr))
{
ssUnlockTsk();
/* store offset of the write pointer */
/* incase subsequent allocations fail, offset is read reset to original */
offset = tmp->b_datap->db_lim - tmp->b_wptr;
/* determine the number of bytes to copy */
numBytes = MIN(cnt, offset);
/* decrement cnt */
cnt -= numBytes;
while (numBytes--)
*tmp->b_wptr++ = *src++;
if (!cnt)
{
minfo->len += len;
RETVALUE(ROK);
}
} else
ssUnlockTsk();
newblk = prevblk = NULLP;
while (cnt)
{
/* allocate a message blk */
if (SGetDBuf(minfo->region, minfo->pool, &curblk) != ROK)
{
while ((curblk = newblk))
{
newblk = newblk->b_cont;
(Void) SPutDBuf(minfo->region, minfo->pool, curblk);
}
if (tmp)
{
tmp->b_wptr = tmp->b_datap->db_lim - offset;
}
RETVALUE(ROUTRES);
}
/* insert curblk in the newblk chain */
if (prevblk)
prevblk->b_cont = curblk; /* stack them down */
else
newblk = curblk;
prevblk = curblk;
/* copy data */
wptr = curblk->b_wptr;
numBytes = MIN(cnt, curblk->b_datap->db_lim - wptr);
/* decrement cnt */
cnt -= numBytes;
while (numBytes--)
*wptr++ = *src++;
curblk->b_wptr = wptr;
}
/* insert newblk chain into mBuf */
if (tmp)
tmp->b_cont = newblk;
else
mBuf->b_cont = newblk;
minfo->endptr = curblk;
/* update length */
minfo->len += len;
RETVALUE(ROK);
}
/*
*
* Fun: SRemPreMsg
*
* Desc: This function copies and then removes one byte of
* data from the beginning of a message.
*
* Ret: ROK - ok
* ROKDNA - ok, data not available
* RFAILED - failed, general (optional)
*
* Notes: if message is empty: message is unchanged. return is ok,
* data not available.
*
* if message is not empty: data is removed from front of
* message, data is returned via pointer to data. message
* length is decremented. return is ok.
*
* File: ss_msg.c
*
*/
#ifdef ANSI
PUBLIC S16 SRemPreMsg
(
Data *dataPtr,
Buffer *mBuf
)
#else
PUBLIC S16 SRemPreMsg(dataPtr, mBuf)
Data *dataPtr;
Buffer *mBuf;
#endif
{
SsMsgInfo *minfo;
Buffer *tmp;
TRC1(SRemPreMsg)
#if (ERRCLASS & ERRCLS_INT_PAR)
/* check data pointer */
if (!dataPtr)
{
SSLOGERROR(ERRCLS_INT_PAR, ESS241, ERRZERO, "SRemPreMsg : Null Buffer");
RETVALUE(RFAILED);
}
/* check message buffer */
if (!mBuf)
{
SSLOGERROR(ERRCLS_INT_PAR, ESS242, ERRZERO, "SRemPreMsg : Null Buffer");
RETVALUE(RFAILED);
}
if (mBuf->b_datap->db_type != SS_M_PROTO)
{
SSLOGERROR(ERRCLS_INT_PAR, ESS243, ERRZERO, "SRemPreMsg : Incorrect\
buffer type");
RETVALUE(RFAILED);
}
#endif
if (!(tmp = mBuf->b_cont))
RETVALUE(ROKDNA);
/* get SsMsgInfo of mBuf */
minfo = (SsMsgInfo *) mBuf->b_rptr;
/* read databyte into dataPtr and incrment read ptr */
*dataPtr = *tmp->b_rptr++;
/* if all data is exhausted, release the blk */
if (tmp->b_rptr == tmp->b_wptr)
{
mBuf->b_cont = tmp->b_cont;
(Void) SPutDBuf(minfo->region, minfo->pool, tmp);
}
/* update SsMsgInfo */
if (!--minfo->len)
minfo->endptr = NULLP;
RETVALUE(ROK);
}
/*
*
* Fun: SRemPstMsg
*
* Desc: This function copies and then removes one byte of
* data from the end of a message.
*
* Ret: ROK - ok
* ROKDNA - ok, data not available
* RFAILED - failed, general (optional)
*
* Notes: if message is empty: message is unchanged. return is ok,
* data not available.
*
* if message is not empty: data is removed from back of
* message, data is returned via pointer to data. message
* length is decremented. return is ok.
*
* File: ss_msg.c
*
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -