home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 200-299 / ff236.lzh / DiskHandler / sendpkt.c < prev    next >
C/C++ Source or Header  |  1989-08-09  |  1KB  |  52 lines

  1. /* From: ConPackets.c -  C. Scheppner, A. Finkel, P. Lindsay  CBM
  2.  *   DOS packet example
  3.  *   Requires 1.2
  4.  * 
  5.  */
  6. #include "handler.h"
  7.  
  8. LONG sendpkt(pid,action,args,nargs)
  9. struct MsgPort *pid;  /* process indentifier ... (handlers message port ) */
  10. LONG action,          /* packet type ... (what you want handler to do )   */
  11.      args[],          /* a pointer to a argument list */
  12.      nargs;           /* number of arguments in list  */
  13.    {
  14.    struct MsgPort        *replyport;
  15.    struct StandardPacket *packet;
  16.  
  17.    LONG  count, *pargs, res1;
  18.  
  19.    replyport = (struct MsgPort *) CreatePort(NULL,0);
  20.    if(!replyport) return(NULL);
  21.  
  22.    packet = (struct StandardPacket *) 
  23.       AllocMem((long)sizeof(struct StandardPacket),MEMF_PUBLIC|MEMF_CLEAR);
  24.    if(!packet) 
  25.       {
  26.       DeletePort(replyport);
  27.       return(NULL);
  28.       }
  29.  
  30.    packet->sp_Msg.mn_Node.ln_Name = (char *)&(packet->sp_Pkt);
  31.    packet->sp_Pkt.dp_Link         = &(packet->sp_Msg);
  32.    packet->sp_Pkt.dp_Port         = replyport;
  33.    packet->sp_Pkt.dp_Type         = action;
  34.  
  35.    /* copy the args into the packet */
  36.    pargs = &(packet->sp_Pkt.dp_Arg1);       /* address of first argument */
  37.    for(count=0;count < nargs;count++) 
  38.       pargs[count]=args[count];
  39.  
  40.    PutMsg(pid,(struct Message *)packet); /* send packet */
  41.  
  42.    WaitPort(replyport);
  43.    GetMsg(replyport); 
  44.  
  45.    res1 = packet->sp_Pkt.dp_Res1;
  46.  
  47.    FreeMem((char *)packet,(long)sizeof(struct StandardPacket));
  48.    DeletePort(replyport); 
  49.  
  50.    return(res1);
  51. }
  52.