MyWebUniversity.com Home Page
 



OpenSolaris man pages main menu


Kernel Functions for Drivers                            copyb(9F)



NAME
     copyb - copy a message block

SYNOPSIS
     #include 



     mblkt *copyb(mblkt *bp);


INTERFACE LEVEL
     Architecture independent level 1 (DI/DKI).

PARAMETERS
     bp    Pointer to  the  message  block  from  which  data  is
           copied.


DESCRIPTION
     The copyb() function allocates  a  new  message  block,  and
     copies  into it the data from the block that bp denotes. The
     new block will be at least  as  large  as  the  block  being
     copied.  copyb() uses the brptr and bwptr members of bp to
     determine how many bytes to copy.

RETURN VALUES
     If successful, copyb() returns a pointer to the newly  allo-
     cated  message  block containing the copied data. Otherwise,
     it returns a NUL pointer.

CONTEXT
     The copyb() function can be called from user, interrupt,  or
     kernel context.

EXAMPLES
     Example 1 Using copyb


     For each message in the list, test to see if the  downstream
     queue is full with the canputnext(9F) function (line 21). If
     it is not full, use copyb to copy a  header  message  block,
     and dupmsg(9F) to duplicate the data to be retransmitted. If
     either operation fails, reschedule a  timeout  at  the  next
     valid interval.



     Update the new header block  with  the  correct  destination
     address  (line  34),  link  the message to it (line 35), and
     send it downstream (line  36).  At  the  end  of  the  list,
     reschedule this routine.



SunOS 5.11          Last change: 16 Jan 2006                    1






Kernel Functions for Drivers                            copyb(9F)



        1  struct retrans {
        2        mblkt             *rmp;
        3        int                raddress;
        4        queuet            *routq;
        5        struct retrans     *rnext;
        6  };
        7
        8  struct protoheader {
              ...
        9     int                    haddress;
              ...
       10  };
       11
       12  mblkt *header;
       13
       14  void
       15  retransmit(struct retrans *ret)
       16  {
       17       mblkt *bp, *mp;
       18       struct protoheader *php;
       19
       20       while (ret) {
       21         if (!canputnext(ret->routq)) {   /* no room */
       22                ret = ret->rnext;
       23                continue;
       24         }
       25         bp = copyb(header);               /* copy header msg. block */
       26         if (bp == NUL)
       27               break;
       28         mp = dupmsg(ret->rmp);           /* duplicate data */
       29         if (mp == NUL) {                 /* if unsuccessful */
       30              freeb(bp);                   /* free the block */
       31              break;
       32         }
       33         php = (struct protoheader *)bp->brptr;
       34         php->haddress = ret->raddress;   /* new header */
       35         bp->bpcont = mp;                  /* link the message */
       36         putnext(ret->routq, bp);          /* send downstream */
       37         ret = ret->rnext;
       38       }
       39       /* reschedule */
       40       (void) timeout(retransmit, (caddrt)ret, RETRANSTIME);
       41  }


SEE ALSO
     allocb(9F), canputnext(9F), dupmsg(9F)


     Writing Device Drivers





SunOS 5.11          Last change: 16 Jan 2006                    2






Kernel Functions for Drivers                            copyb(9F)



     STREAMS Programming Guide






















































SunOS 5.11          Last change: 16 Jan 2006                    3



OpenSolaris man pages main menu

Contact us      |       About us      |       Term of use      |       Copyright © 2000-2010 MyWebUniversity.com ™