home *** CD-ROM | disk | FTP | other *** search
/ The CDPD Public Domain Collection for CDTV 4 / CDPD_IV.bin / networking / dnet / dnet2.3.2 / amiga / lib / makechannel.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-29  |  2.0 KB  |  80 lines

  1.  
  2. /*
  3.  *  MakeChannel.C
  4.  *
  5.  *  (internal routine)
  6.  */
  7.  
  8. #include "lib.h"
  9.  
  10. /* this is rather bogus, and completely unused... */
  11. short    DUseSignal = -1;
  12.  
  13. /* uh, use CreatePort in this? */
  14.  
  15. void *
  16. MakeChannel(ior, host)
  17. IOSTD *ior;
  18. char *host;
  19. {
  20.     CHANN *chan = AllocMem(sizeof(CHANN), MEMF_PUBLIC|MEMF_CLEAR);
  21.  
  22.     IFDEBUG(printf("Making a channel to host %s\n", host);)
  23.  
  24.     if(chan == NULL) return NULL;
  25.  
  26.     /* create and initialize channel's message port */
  27.  
  28.     chan->port.mp_Node.ln_Type = NT_MSGPORT; /* it's a message port */
  29.  
  30.     /*  set the signal that this channel's port will use */
  31.     if (DUseSignal >= 0)
  32.     chan->port.mp_SigBit = DUseSignal;
  33.     else 
  34.     {
  35.         int sigbit;
  36.         if((sigbit = AllocSignal(-1)) != -1)
  37.         chan->port.mp_SigBit = sigbit;
  38.     else {
  39.         printf("MakeChannel(): Failed to AllocSignal for new channel!\n");
  40.         FreeMem( chan, sizeof(CHANN));
  41.         return NULL;
  42.     }
  43.     }
  44.  
  45.     chan->port.mp_SigTask = FindTask(NULL);  /* signals will go to this task */
  46.  
  47.     NewList(&chan->port.mp_MsgList);   /* Initialize this port's list */
  48.  
  49.     NewList(&chan->rdylist);            /* Init list of items ready to be read */
  50.     chan->chan = (ulong)ior->io_Unit; /* set the the unit of the new channel */
  51.     ior->io_Offset = (ulong)chan;      /* Uh, why? */
  52.  
  53.     if (host) {
  54.     char buf[sizeof(DNETPORTNAME)+32];
  55.     sprintf(buf, "%s%s", DNETPORTNAME, host);
  56.     Forbid();
  57.     ior->io_Message.mn_ReplyPort = FindPort(buf);
  58.     Permit();
  59.     IFDEBUG(printf("Set ior's reply port to port for \"%s\"\n", buf);)
  60.     }
  61.     chan->dnetport = ior->io_Message.mn_ReplyPort;
  62.     IFDEBUG(if(chan->dnetport == NULL)printf("dnetport not set!\n");)
  63.  
  64.     return((void *)chan);
  65. }
  66.  
  67. void
  68. DeleteChannel(_chan)
  69. void *_chan;
  70. {
  71.     CHANN *chan = (CHANN *)_chan;
  72.  
  73.     IFDEBUG(printf("Deleting channel %lx\n", chan);)
  74.     if (chan->port.mp_SigBit != DUseSignal)
  75.     FreeSignal(chan->port.mp_SigBit);
  76.     IFDEBUG(printf("channel signal freed\n", chan);)
  77.     FreeMem(chan, sizeof(CHANN));
  78.     IFDEBUG(printf("channel freed (%d byts) \n", sizeof(CHANN) );)
  79. }
  80.