home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 3 / goldfish_volume_3.bin / files / comm / tcp / amitcp / src / l / inet-handler / handler / startup.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-17  |  3.4 KB  |  115 lines

  1. /* $Id: startup.c,v 3.3 1994/04/17 11:57:57 too Exp $
  2.  *
  3.  * Copyright (c) 1993 AmiTCP/IP Group <amitcp-group@hut.fi>
  4.  *
  5.  * Created: Wed Nov 10 13:05:10 1993 too
  6.  * Last Modified: Sun Apr 17 12:39:31 1994 too
  7.  */
  8. {
  9.   struct DosPacket *    packet;
  10.   struct DosLibrary *    l_DOSBase;
  11.  
  12.   SysBase = *(struct ExecBase **)4;
  13.  
  14.   bzero((char *)&CU, sizeof CU);
  15.   /*
  16.    * Give initials values to cleanup variables. The ones not mentioned
  17.    * here are initialized to zero.
  18.    */
  19.   applsigbit = -1;
  20.   NewList((struct List *)&freeappllist);
  21.   NewList((struct List *)&writelist);
  22.   NewList((struct List *)&freewritelist);
  23.  
  24.   applcbcur = 0;
  25.   applcbpos = 0;
  26.  
  27.   if ((l_DOSBase = (struct DosLibrary *)OpenLibrary("dos.library", 37))
  28.       == NULL)
  29.     /* in fact this cannot happen (cannot receive startup packet) */
  30.     return 100;
  31.   else
  32.     /*
  33.      * NOTE: For historical reasons returned DOSBase address will always
  34.      *         be the same. (In future binary compatible amiga systems too)
  35.      */
  36.     DOSBase = l_DOSBase;
  37.  
  38. #ifdef __SASC
  39.   mymsgport = mkDevice("TCP", 3);
  40. #else
  41.   packet = WaitPkt(); /* get handler startup packet */
  42. #endif
  43.   /*
  44.    * Now try to open socket library for network communication.
  45.    */
  46.   if ((SocketBase = OpenLibrary("bsdsocket.library", 3)) == NULL) {
  47.     ReplyPkt(packet, DOSFALSE, ERROR_NO_DISK);
  48.     return clean(&CU, 20);
  49.   }
  50.   (void)SocketBaseTagList(dtablesizetaglist);
  51.   /*
  52.    * Create reply port for timer message and open the timer.device.
  53.    * The IORequest itr is filled with timer devise info that is copied
  54.    * to each timerequest si ot can do IO with timer.device.
  55.    */
  56.   if (((timermsgport = CreateMsgPort()) == NULL) ||
  57.       ((itr = AllocMem(sizeof *itr, MEMF_PUBLIC|MEMF_CLEAR)) == NULL)) {
  58.     ReplyPkt(packet, DOSFALSE, ERROR_NO_FREE_STORE);
  59.     return clean(&CU, 20);
  60.   }
  61.  
  62.   if (OpenDevice(TIMERNAME, UNIT_VBLANK, itr, 0) != 0) {
  63.     FreeMem(itr, sizeof *itr);
  64.     itr = NULL; /* NULL so clean() doesn't try to close the device */
  65.     ReplyPkt(packet, DOSFALSE, ERROR_NO_FREE_STORE);
  66.     return clean(&CU, 20);
  67.   }
  68.  
  69.   timerflag = 1 << timermsgport->mp_SigBit;
  70.   itr->io_Command = TR_ADDREQUEST;
  71.   itr->io_Message.mn_ReplyPort = timermsgport;
  72.  
  73.   /*
  74.    * A new messageport is created for each application, but they all
  75.    * share a common signal.
  76.    */
  77.   if ((applsigbit = AllocSignal(-1)) == -1) {
  78.     ReplyPkt(packet, DOSFALSE, ERROR_NO_FREE_STORE);
  79.     return clean(&CU, 20);
  80.   }
  81.   applportflag = 1 << applsigbit;
  82.  
  83.   /*
  84.    * New instance startup packets comes to handler startup message
  85.    * port (since mydev-dol_Task is set to it) I.e. this one handler
  86.    * process is (currently) handling all new instances.
  87.    * Data arriving to sockets are handled the usual BSD select() way.
  88.    */
  89.   me = FindTask(NULL);
  90.  
  91. #ifndef __SASC
  92.   mymsgport = &((struct Process *)me)->pr_MsgPort;
  93.   myportflag = 1 << mymsgport->mp_SigBit;
  94.   mydev = (struct DosList *)BADDR(packet->dp_Arg3);
  95.   mydev->dol_Task = mymsgport;
  96.  
  97.   /*
  98.    * Reply startup packet after successfull initialization.
  99.    */
  100.   ReplyPkt(packet, DOSTRUE, packet->dp_Arg2);
  101. #else
  102.   myportflag = 1 << mymsgport->mp_SigBit;
  103. #endif
  104.  
  105.   /*
  106.    * Initial settings: read and write descriptor sets are cleared,
  107.    * nfds set to 0, indicating no sockets are created and
  108.    * signal mask is set to listen open packets from handler user programs.
  109.    */
  110.   FD_ZERO(&readfds);
  111.   FD_ZERO(&writefds);
  112.   nfds = 0;
  113.   sigmask = myportflag | applportflag | timerflag;
  114. }
  115.