copyb(D3)copyb(D3)NAMEcopyb - copy a message block
SYNOPSIS
#include <sys/stream.h>
#include <sys/ddi.h>
mblk_t *copyb(mblk_t *bp);
Arguments
bp Pointer to the message block from which data are copied.
DESCRIPTIONcopyb allocates a new message block, and copies into it the data from the
block pointed to by bp. The new block will be at least as large as the
block being copied. The b_rptr and b_wptr members of the message block
pointed to by bp are used to determine how many bytes to copy.
Return Values
On success, copyb returns a pointer to the newly allocated message block
containing the copied data. On failure, it returns a NULL pointer.
USAGE
Level
Base or Interrupt.
Synchronization Constraints
Does not sleep.
Driver-defined basic locks, read/write locks, and sleep locks may be held
across calls to this function.
Example
This example illustrates how copyb can be used during message
retransmission. If there are no messages to retransmit, we return (line
18). For each retransmission record in the list, we test to see if the
downstream queue is full with the canput(D3) function (line 21). If it
is full, we skip the current retransmission record and continue searching
the list. If it is not full, we use copyb(D3) to copy a header message
block (line 25), and dupmsg(D3) to duplicate the data to be retransmitted
(line 28). If either operation fails, we clean up and break out of the
loop.
Otherwise, we update the new header block with the correct destination
address (line 34), link the message to be retransmitted to it (line 35),
and send it downstream (line 36). At the end of the list, we reschedule
a itimeout at the next valid interval (line 39) and return.
1 struct retrns {
2 mblk_t *r_mp; /* message to retransmit */
3 long r_address; /* destination address */
4 queue_t *r_outq; /* output queue */
5 struct retrns *r_next; /* next retransmission */
Page 1
copyb(D3)copyb(D3)
6 };
7 struct protoheader {
8 long h_address; /* destination address */
...
9 };
10 mblk_t *header;
11 struct retrns *rlist;
...
12 retransmit()
13 {
14 mblk_t *bp, *mp;
15 struct retrns *rp;
16 struct protoheader *php;
17 if (!rlist)
18 return;
19 rp = rlist;
20 while (rp) {
21 if (!canput(rp->r_outq->q_next)) {
22 rp = rp->r_next;
23 continue;
24 }
25 bp = copyb(header);
26 if (bp == NULL)
27 break;
28 mp = dupmsg(rp->r_mp);
29 if (mp == NULL) {
30 freeb(bp);
31 break;
32 }
33 php = (struct protoheader *)bp->b_rptr;
34 php->h_address = rp->r_address;
35 bp->bp_cont = mp;
36 putnext(rp->r_outq, bp);
37 rp = rp->r_next;
38 }
39 (void) itimeout(retransmit, 0, RETRNS_TIME, plstr);
40 }
REFERENCESallocb(D3), copymsg(D3), msgb(D4)
Page 2