1copyb(9F)                Kernel Functions for Drivers                copyb(9F)
2
3
4

NAME

6       copyb - copy a message block
7

SYNOPSIS

9       #include <sys/stream.h>
10
11
12
13       mblk_t *copyb(mblk_t *bp);
14
15

INTERFACE LEVEL

17       Architecture independent level 1 (DDI/DKI).
18

PARAMETERS

20       bp    Pointer to the message block from which data is copied.
21
22

DESCRIPTION

24       The  copyb() function allocates a new message block, and copies into it
25       the data from the block that bp denotes. The new block will be at least
26       as  large as the block being copied. copyb() uses the b_rptr and b_wptr
27       members of bp to determine how many bytes to copy.
28

RETURN VALUES

30       If successful, copyb() returns a pointer to the newly allocated message
31       block containing the copied data. Otherwise, it returns a NULL pointer.
32

CONTEXT

34       The copyb() function can be called from user, interrupt, or kernel con‐
35       text.
36

EXAMPLES

38       Example 1 Using copyb
39
40
41       For each message in the list, test to see if the  downstream  queue  is
42       full with the canputnext(9F) function (line 21). If it is not full, use
43       copyb to copy a header message block, and dupmsg(9F) to  duplicate  the
44       data to be retransmitted. If either operation fails, reschedule a time‐
45       out at the next valid interval.
46
47
48
49       Update the new header block with the correct destination address  (line
50       34),  link  the  message  to it (line 35), and send it downstream (line
51       36). At the end of the list, reschedule this routine.
52
53
54          1  struct retrans {
55          2        mblk_t             *r_mp;
56          3        int                r_address;
57          4        queue_t            *r_outq;
58          5        struct retrans     *r_next;
59          6  };
60          7
61          8  struct protoheader {
62                ...
63          9     int                    h_address;
64                ...
65         10  };
66         11
67         12  mblk_t *header;
68         13
69         14  void
70         15  retransmit(struct retrans *ret)
71         16  {
72         17       mblk_t *bp, *mp;
73         18       struct protoheader *php;
74         19
75         20       while (ret) {
76         21         if (!canputnext(ret->r_outq)) {   /* no room */
77         22                ret = ret->r_next;
78         23                continue;
79         24         }
80         25         bp = copyb(header);               /* copy header msg. block */
81         26         if (bp == NULL)
82         27               break;
83         28         mp = dupmsg(ret->r_mp);           /* duplicate data */
84         29         if (mp == NULL) {                 /* if unsuccessful */
85         30              freeb(bp);                   /* free the block */
86         31              break;
87         32         }
88         33         php = (struct protoheader *)bp->b_rptr;
89         34         php->h_address = ret->r_address;   /* new header */
90         35         bp->bp_cont = mp;                  /* link the message */
91         36         putnext(ret->r_outq, bp);          /* send downstream */
92         37         ret = ret->r_next;
93         38       }
94         39       /* reschedule */
95         40       (void) timeout(retransmit, (caddr_t)ret, RETRANS_TIME);
96         41  }
97
98

SEE ALSO

100       allocb(9F), canputnext(9F), dupmsg(9F)
101
102
103       Writing Device Drivers
104
105
106       STREAMS Programming Guide
107
108
109
110SunOS 5.11                        16 Jan 2006                        copyb(9F)
Impressum