home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 3 / goldfish_volume_3.bin / files / comm / tcp / amitcp / src / l / inet-handler / handler / cleanup.c < prev    next >
Encoding:
Text File  |  1994-04-17  |  2.7 KB  |  99 lines

  1. /* $Id: cleanup.c,v 1.3 1994/04/17 11:55:50 too Exp $
  2.  *
  3.  * Copyright (c) 1993 AmiTCP/IP Group <amitcp-group@hut.fi>
  4.  *
  5.  * Created: Wed Nov 10 13:48:06 1993 too
  6.  * Last modified: Sun Apr 17 12:40:32 1994 too
  7.  */
  8. {
  9.   {
  10.     int i;
  11.     int ocnt;
  12.  
  13.     CloseLibrary(SocketBase);
  14.     SocketBase = NULL;
  15.     
  16.     for (i = 0, ocnt = nfds; i < nfds; i++) {
  17.       struct ApplPort * applport = applarray[i];
  18.       if (applport->ap_Pw) {
  19.     ReplyPkt(applport->ap_Pw->pw_Packet, 0, 0);
  20.     FreeMem(applport->ap_Pw, sizeof (struct PendingWrites));
  21.       }
  22.       if (applport->ap_Packet)
  23.     switch (applport->ap_Packet->dp_Type) {
  24.     case ACTION_FINDINPUT:
  25.     case ACTION_FINDOUTPUT: /* listening and holding Open() packet */
  26.     case ACTION_FINDUPDATE:
  27.       ReplyPkt(applport->ap_Packet, DOSFALSE, ERROR_NO_MORE_ENTRIES);
  28.       FreeMem(applport, sizeof (struct ApplPort));
  29.       ocnt--;
  30.       break;
  31.     case ACTION_WAIT_CHAR:
  32.       Abort_Timeout(&applport->ap_Tr);
  33.       /* FALL THROUGH... */
  34.     default: /* perhaps only ACTION_READ */
  35.       ReplyPkt(applport->ap_Packet, -1, ERROR_NO_MORE_ENTRIES);
  36.     }
  37.     }
  38.     nfds = ocnt;
  39.   }
  40.   For_Each_List_Item_CacheNext(&freeappllist, void *, item,
  41.                    FreeMem(item,
  42.                        sizeof (struct ApplPort)); );
  43.   For_Each_List_Item_CacheNext(&freewritelist, void *, item,
  44.                    FreeMem(item,
  45.                        sizeof (struct PendingWrites)); );
  46.   sigmask = myportflag | applportflag;
  47.   while(nfds > 0) {
  48.     ULONG smask = Wait(sigmask);
  49.     if (smask & myportflag) {
  50.       struct Message * msg;
  51.       /*
  52.        * New Open() packets. Reply w/ FALSE immediately.
  53.        */
  54.       while((msg = GetMsg(mymsgport)) != NULL)
  55.     ReplyPkt(msgToPkt(msg), DOSFALSE, ERROR_NO_MORE_ENTRIES);
  56.     }
  57.     if (smask & applportflag) {
  58.       /*
  59.        * Packets to ports of applications. Handle Close() packets.
  60.        */
  61.       while(applcbcur != applcbpos) {
  62.     struct Message * msg;
  63.     struct ApplPort * applport;
  64.  
  65.     applport = directIndex(struct ApplPort *, applcbbuf, applcbcur);
  66.     applcbcur += sizeof (struct ApplPort *);
  67.     applcbcur &= 0x3f * sizeof (struct ApplPort *);
  68.  
  69.     if ((msg = GetMsg(&applport->ap_AMP.amp_Msgport)) != NULL) {
  70.       struct DosPacket * packet = msgToPkt(msg);
  71.  
  72.       DP("pktType: %ld", packet->dp_Type);
  73.       switch(packet->dp_Type) {
  74.       case ACTION_END:
  75.         if (--applport->ap_OpenCnt == 0) {
  76.           FreeMem(applport, sizeof (struct ApplPort));
  77.           nfds--;
  78.         }
  79.         ReplyPkt(packet, DOSTRUE, 0);
  80.         break;
  81.       default:
  82.         ReplyPkt(packet, DOSFALSE, ERROR_NO_MORE_ENTRIES);
  83.         break;
  84.       }
  85.     }
  86.       }
  87.     }
  88.   }
  89.   mydev->dol_Task = 0; /* ATOMIC */
  90.   /*
  91.    * Check if there is still some Open() packets.
  92.    */
  93.   {
  94.     struct Message * msg;
  95.     while((msg = GetMsg(mymsgport)) != NULL)
  96.       ReplyPkt(msgToPkt(msg), DOSFALSE, ERROR_NO_MORE_ENTRIES);
  97.   }
  98. }
  99.