home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 2: PC / frozenfish_august_1995.bin / bbs / d01xx / d0128.lha / MRBackup / sendpkt.c < prev    next >
C/C++ Source or Header  |  1988-01-02  |  2KB  |  63 lines

  1. /* Filename:    sendpkt.c
  2.  * Authors:        Andy Finkel, Phil Lindsay, Commodore-Amiga
  3.  * Date:        06/29/87
  4.  *
  5.  * This package was derived from "touch.c", written by Andy Finkel
  6.  * and Phil Lindsay of Commodore-Amiga.  
  7.  */
  8.  
  9. #include "exec/types.h"
  10. #include "exec/ports.h"
  11. #include "exec/io.h"
  12. #include "exec/memory.h"
  13. #include "libraries/dos.h"
  14. #include "libraries/dosextens.h"
  15.  
  16. #ifdef AZTEC_C
  17. #include <functions.h>
  18. #endif
  19.  
  20. LONG 
  21. sendpkt(id,type,args,nargs)
  22.     struct MsgPort *id;                /* process indentifier ... (handler's
  23.                                        message port ) */
  24.     LONG type,                        /* packet type ... (what you want 
  25.                                        handler to do )   */
  26.     args[],                            /* a pointer to argument list */
  27.     nargs;                            /* number of arguments in list  */
  28. {
  29.  
  30.     struct MsgPort     *replyport;
  31.     struct StandardPacket  *packet;
  32.  
  33.     LONG count,*pargs,res1=NULL;
  34.  
  35.     if (!(replyport = (struct MsgPort   *) CreatePort(NULL,NULL)))
  36.         return(NULL);
  37.  
  38.     packet = (struct StandardPacket *)
  39.                AllocMem((LONG)sizeof(*packet),MEMF_PUBLIC|MEMF_CLEAR);
  40.  
  41.     if (packet) {
  42.         packet->sp_Msg.mn_Node.ln_Name = &(packet->sp_Pkt);/* link packet */
  43.         packet->sp_Pkt.dp_Link = &(packet->sp_Msg);/* to message    */
  44.         packet->sp_Pkt.dp_Port = replyport;/* set-up reply port   */
  45.         packet->sp_Pkt.dp_Type = type;/* what to do... */
  46.  
  47.     /* move all the arguments to the packet */
  48.         pargs = &(packet->sp_Pkt.dp_Arg1);/* address of first argument */
  49.         for (count=0; (count < nargs) && (count < 7); count++)
  50.             pargs[count] = args[count];
  51.  
  52.         PutMsg(id,packet);            /* send packet */
  53.         WaitPort(replyport);        /* wait for packet to come back */
  54.         GetMsg(replyport);            /* pull message */
  55.  
  56.         res1 = packet->sp_Pkt.dp_Res1;/* get result */
  57.         FreeMem(packet,(LONG)sizeof(*packet));
  58.  
  59.     }
  60.     DeletePort(replyport);
  61.     return(res1);
  62. }
  63.