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

  1. /* $Id: mymsg.c,v 1.2 1994/04/17 11:53:44 too Exp $
  2.  *
  3.  * Copyright (c) 1993 AmiTCP/IP Group <amitcp-group@hut.fi>
  4.  *
  5.  * Created: Wed Nov 10 13:29:00 1993 too
  6.  * Last modified: Wed Apr 13 16:01:36 1994 too
  7.  */
  8. {
  9.   struct Message * msg;
  10.  
  11.   while ((msg = GetMsg(mymsgport)) != NULL) {
  12.     struct DosPacket *    packet = msgToPkt(msg);
  13.     struct ApplPort *    applport;
  14.     char *    name;
  15.     UBYTE    namelen;
  16.     LONG    flags = 0;
  17.     LONG    ioErr;
  18.  
  19.     switch (packet->dp_Type) {
  20.  
  21.     case ACTION_FINDINPUT:
  22.     case ACTION_FINDOUTPUT:
  23.     case ACTION_FINDUPDATE:
  24.       /*
  25.        * get given handler name. Reopen packets doesn't come here.
  26.        */
  27.  
  28.       /* Get given handler name. can be real name or *, or 'CONSOLE:'
  29.        * 2 last mentioned in reopen case. First byte in argument 3
  30.        * in received packet is namelen and rest bytes are the name.
  31.        */
  32.       name = (UBYTE *)BADDR(packet->dp_Arg3);
  33.       namelen = *name++;
  34.  
  35.       /*
  36.        * getting new connection object.
  37.        */
  38.       if ((applport = getBuffer((struct List *)&freeappllist,
  39.                 sizeof (struct ApplPort))) == NULL) {
  40.     ReplyPkt(packet, DOSFALSE, ERROR_NO_FREE_STORE);
  41.     break;
  42.       }
  43.  
  44.       if ((ioErr = handleArgs(SocketBase, &flags,
  45.                   &applport->ap_Sd, name, namelen)) != 0) {
  46.     AddTail((struct List *)&freeappllist, (struct Node *)applport);
  47.     ReplyPkt(packet, DOSFALSE, ioErr);
  48.       }
  49.       else {
  50.     /*
  51.      * Initialize some fields in applstruct.
  52.      */
  53.     applarray[applport->ap_Sd] = applport;
  54.     applport->ap_AS = &AS;
  55.     applport->ap_Pw = NULL;
  56.     applport->ap_Disb = FALSE;
  57.     applport->ap_OpenCnt = 1;
  58.     /*
  59.      * Set new socket to active read sockets.
  60.      */
  61.     nfds++;
  62.  
  63.     FD_SET(applport->ap_Sd, &readfds);
  64.  
  65.     initApplMsgPort(&applport->ap_AMP);
  66.     /*
  67.      * Copy timer.device information to IORequest part
  68.      * of applport's timerequest field.
  69.      */
  70.     CopyMem(itr, &applport->ap_Tr, sizeof *itr);
  71.     /* (struct IORequest)applport->ap_Tr = *itr; */
  72.  
  73.     /*
  74.      * Reply 'Open' packet only if connection already made.
  75.      */
  76.     if (flags & APF_LISTENING)
  77.       applport->ap_Packet = packet; /* values set after accept() */
  78.     else {
  79.       struct FileHandle * fh =
  80.         (struct FileHandle *)BADDR(packet->dp_Arg1);
  81.       /*
  82.        * Set MsgPort ptr of Open() FileHandle to point the
  83.        *  messageport allocated for this connection.
  84.        */
  85.       fh->fh_Port = (struct MsgPort *)DOSTRUE; /* IsInteractive() */
  86.       fh->fh_Type = &applport->ap_AMP.amp_Msgport;
  87.       IoctlSocket(applport->ap_Sd, FIONBIO, (char *)&one);
  88.       setsockopt(applport->ap_Sd,
  89.              SOL_SOCKET, SO_OOBINLINE, (char *)&one, sizeof one);
  90.       applport->ap_Packet = NULL;
  91.       ReplyPkt(packet, DOSTRUE, packet->dp_Res2);
  92.     }
  93.       }
  94.       break;
  95.     case ACTION_IS_FILESYSTEM:
  96.       ReplyPkt(packet, DOSFALSE, 0);
  97.       break;
  98.     default:
  99.       /*
  100.        * Other messages comes to separate messageport.
  101.        * each 'channel' has their own for identification reasons.
  102.        * (this is good reply for ACTION_LOCATE_OBJECT)
  103.        */
  104.       ReplyPkt(packet, DOSFALSE, ERROR_ACTION_NOT_KNOWN);
  105.       break;
  106.     }
  107.   }
  108. }
  109.