home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 2: PC / frozenfish_august_1995.bin / bbs / d02xx / d0248.lha / NetHandler / iodnet.c < prev    next >
C/C++ Source or Header  |  1989-09-16  |  4KB  |  156 lines

  1. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\
  2. * |_o_o|\\ Copyright (c) 1988 The Software Distillery.  All Rights Reserved *
  3. * |. o.| ||          Written by Doug Walker                                 *
  4. * | .  | ||          The Software Distillery                                *
  5. * | o  | ||          235 Trillingham Lane                                   *
  6. * |  . |//           Cary, NC 27513                                         *
  7. * ======             BBS:(919)-471-6436                                     *
  8. \* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  9. #define NETCOMMON
  10. #include "netdnet.h"
  11. #include "netcomm.h"
  12. #include "proto.h"
  13.  
  14. int PutRPacket(global, ioptr)
  15. NGLOBAL global;
  16. APTR ioptr;
  17. {
  18.    int len;
  19.  
  20.    BUG(("PutRPacket: type %d, Args %lx %lx %lx %lx\n", global->RP.Type, 
  21.        global->RP.Arg1, global->RP.Arg2, 
  22.        global->RP.Arg3, global->RP.Arg4));
  23.  
  24.  
  25. TOP:
  26.    BUG(("PutRPacket: writing %d to %lx. . .", RPSIZE, ioptr));
  27.    if((len=DWrite((struct DChannel *)ioptr,
  28.                    (char *)&global->RP, RPSIZE)) != RPSIZE)
  29.    {
  30.       BUG(("**********ERROR - wrote %d instead\n", len));
  31.       BUGR("Write error");
  32.       if(ReSync(global, ioptr)) return(1);
  33.       else goto TOP;
  34.    }
  35.    BUG(("%d written\n", len));
  36.  
  37.    if(global->RP.DLen)
  38.    {
  39.       BUG(("PutRPacket: writing %d to %lx. . .", global->RP.DLen, ioptr));
  40.       if((len=DWrite((struct DChannel *)ioptr,
  41.                      global->RP.Data, global->RP.DLen)) != global->RP.DLen)
  42.       {
  43.          BUG(("**********ERROR - wrote %d instead\n", len));
  44.          BUGR("Write error 2");
  45.          if(ReSync(global, ioptr)) return(1);
  46.          else goto TOP;
  47.       }
  48.       BUG(("%d written\n", len));
  49.    }
  50.  
  51.    if(global->n.infoport)
  52.    {
  53.       struct Message *m;
  54.       while(m=GetMsg(global->n.ntirec.m.mn_ReplyPort))
  55.       {
  56.          if(m == &global->n.ntirec.m)
  57.             global->n.inuse_rec = 0;
  58.          else
  59.             global->n.inuse_trans = 0;
  60.       }
  61.       global->n.inf_trans += RPSIZE + global->RP.DLen;
  62.          
  63.       if(!global->n.inuse_trans)
  64.       {
  65.          BUG(("PutRPacket: Writing status info to port %lx: TRANSMIT %ld\n", 
  66.             global->n.infoport, global->n.inf_trans))
  67.  
  68.          global->n.ntitrans.nti_bytes = global->n.inf_trans;
  69.          global->n.ntitrans.nti_direction = NTI_TRANSMIT;
  70.          PutMsg(global->n.infoport, &global->n.ntitrans.m);
  71.  
  72.          global->n.inuse_trans = 1;
  73.          global->n.inf_trans = 0;
  74.       }
  75. #if DEBUG
  76.       else
  77.          BUG(("PutRPacket: Skipping status write, packet outstanding\n"))
  78. #endif
  79.    }
  80.  
  81.    return(0);
  82. }
  83.  
  84. int GetRPacket(global, ioptr)
  85. NGLOBAL global;
  86. APTR ioptr;
  87. {
  88.    int len;
  89.  
  90.    BUG(("GetRPacket: reading %d from %lx. . .", RPSIZE, ioptr));
  91.  
  92. TOP:
  93.    if((len=DRead((struct DChannel *)ioptr, 
  94.                  (char *)&global->RP, RPSIZE)) != RPSIZE)
  95.    {
  96.       BUG(("**********ERROR - read %d instead\n", len));
  97.       BUGR("Read error")
  98.       if(ReSync(global, ioptr)) return(1);
  99.       else goto TOP;
  100.    }
  101.  
  102.    BUG(("type %d, Args %lx %lx %lx %lx\n", global->RP.Type, 
  103.        global->RP.Arg1, global->RP.Arg2, 
  104.        global->RP.Arg3, global->RP.Arg4));
  105.  
  106.    if(global->RP.DLen > 0) 
  107.    {
  108.       BUG(("Reading %d more. . .", global->RP.DLen));
  109.       if((len=DRead((struct DChannel *)ioptr, 
  110.              global->RP.Data, global->RP.DLen)) != global->RP.DLen)
  111.       {
  112.          BUG(("**********ERROR - read %d instead\n", len));
  113.          BUGR("Read error 2")
  114.          if(ReSync(global, ioptr)) return(1);
  115.          else goto TOP;
  116.       }
  117.    }
  118.    else
  119.       global->RP.Data[0] = '\0';
  120.  
  121.    BUG(("Done\n"))
  122.  
  123.    if(global->n.infoport)
  124.    {
  125.       struct Message *m;
  126.       while(m=GetMsg(global->n.ntirec.m.mn_ReplyPort))
  127.       {
  128.          if(m == &global->n.ntirec.m)
  129.             global->n.inuse_rec = 0;
  130.          else
  131.             global->n.inuse_trans = 0;
  132.       }
  133.       global->n.inf_rec += RPSIZE + global->RP.DLen;
  134.          
  135.       if(!global->n.inuse_rec)
  136.       {
  137.          BUG(("GetRPacket: Writing status info to port %lx: RECEIVE %ld\n",
  138.             global->n.infoport, global->n.inf_rec))
  139.  
  140.          global->n.ntirec.nti_bytes = global->n.inf_rec;
  141.          global->n.ntirec.nti_direction = NTI_RECEIVE;
  142.          PutMsg(global->n.infoport, &global->n.ntirec.m);
  143.  
  144.          global->n.inuse_rec = 1;
  145.          global->n.inf_rec = 0;
  146.       }
  147. #if DEBUG
  148.       else
  149.          BUG(("GetRPacket: Skipping status write, packet outstanding\n"))
  150. #endif
  151.    }
  152.  
  153.    return(0);
  154. }
  155.  
  156.