home *** CD-ROM | disk | FTP | other *** search
/ Network Support Encyclopedia 96-1 / novell-nsepro-1996-1-cd2.iso / download / netware / dax1.exe / CP / CPC / CPSEND.C < prev    next >
Text File  |  1992-07-15  |  6KB  |  152 lines

  1. //   ╔════════════════════════════════════════════════════════════════════╗
  2. //   ║                                                                    ║
  3. //   ║ module:      cpsend.c                                              ║
  4. //   ║ abstract:    This module contains the APIs to send messages.       ║
  5. //   ║                                                                    ║
  6. //   ║ environment: NetWare 3.x v3.11                                     ║
  7. //   ║              Network C for NLMs SDK v2.0d                          ║
  8. //   ║              CLib v3.11                                            ║
  9. //   ║              Network C for DOS v2.0                                ║
  10. //   ║              NetWare C Interface DOS v1.2                          ║
  11. //   ║                                                                    ║
  12. //   ║  This software is provided as is and carries no warranty           ║
  13. //   ║  whatsoever.  Novell disclaims and excludes any and all implied    ║
  14. //   ║  warranties of merchantability, title and fitness for a particular ║
  15. //   ║  purpose.  Novell does not warrant that the software will satisfy  ║
  16. //   ║  your requirements or that the software is without defect or error ║
  17. //   ║  or that operation of the software will be uninterrupted.  You are ║
  18. //   ║  using the software at your risk.  The software is not a product   ║
  19. //   ║  of Novell, Inc. or any of subsidiaries.                           ║
  20. //   ║                                                                    ║
  21. //   ╟────────────────────────────────────────────────────────────────────╢
  22. //   ║ maintenance history:                                               ║
  23. //   ║ level    date      pi   description                                ║
  24. //   ╟────────────────────────────────────────────────────────────────────╢
  25. //   ║  001   01/24/92    kl   initial release.                           ║
  26. //   ║  002   07/14/92    kl   windows port.                              ║
  27. //   ╚════════════════════════════════════════════════════════════════════╝
  28.  
  29. #include <stdio.h>
  30. #include <stdlib.h>
  31. #include <string.h>
  32. #include <process.h>
  33. #include "cp/cpsys.h"
  34. #include <nwmisc.h>
  35.  
  36. //------------------------------------------------------------------------
  37. //
  38. //  This API locates one of the 'send' structures that is free
  39. //
  40. STATIC  CPCOMMDATA  *CPFindFreeCPCommData(CPDATA *CPid)
  41. {
  42.         int     i;
  43.  
  44.         for(i=0; i < CPCNUMSENDECBS; ++i)
  45.             if( !ECBISINUSE(&CPid->sends[i].ecb) ) return &CPid->sends[i];
  46.         return NULL;
  47. }
  48.  
  49. //------------------------------------------------------------------------
  50. //
  51. //  This API initializes a send ECB. i.e. readies it for transport...
  52. //
  53. void    CPInitSendPacket(WORD       socket,
  54.                          ECB        *ecb, 
  55.                          IPXHeader  *packet,
  56.                          void       *request, 
  57.                          WORD       sizeRequest, 
  58.                          IPXAddress *destination)
  59. {
  60.     #if defined(DOSCLIENT) || defined(WINCLIENT)
  61.         packet->destination = *destination;
  62.     #elif defined(NLMCLIENT)
  63.         *(IPXAddress *)&packet->destNet = *destination;
  64.     #endif
  65.         packet->packetType  = 4;
  66.         ECBFRAGCOUNT(ecb)   = 2;
  67.         ECBSOCKET(ecb)      = socket;
  68.         ECBFRAGADDR(ecb,0)  = packet;
  69.         ECBFRAGSIZE(ecb,0)  = sizeof(IPXHeader);
  70.         ECBFRAGADDR(ecb,1)  = request;
  71.         ECBFRAGSIZE(ecb,1)  = sizeRequest;
  72. }
  73.  
  74. //------------------------------------------------------------------------
  75. //
  76. //  This API gets the CP Layer ready to send data to the server
  77. //
  78. T_RC    CPInitializeSendLogic(CPDATA *CPid)
  79. {
  80.         int     i;
  81.         //
  82.         //  Get two send ECBs ready.  One for sending requests, and one
  83.         //  for sending replies.  This implementation only needs one,
  84.         //  since we don't support sending replies from the client.
  85.         //
  86.         for(i=0; i < CPCNUMSENDECBS; ++i){
  87.             CPInitSendPacket(CPid->skt,
  88.                              &CPid->sends[i].ecb,
  89.                              &CPid->sends[i].ipx,
  90.                              &CPid->sends[i].cpmsg,
  91.                              sizeof CPid->sends[i].cpmsg,
  92.                              &CPid->ipxaddr);
  93.         }
  94.         return CP_SUCCESS;
  95. }
  96.  
  97. //------------------------------------------------------------------------
  98. //
  99. //  This API sends a request to the server
  100. //
  101. T_RC    CPSendMessage(CPDATA *CPid, void *data, unsigned length)
  102. {
  103.         int         tTime;
  104.         WORD        startTicks,endTicks;
  105.         CPCOMMDATA  *c = CPFindFreeCPCommData(CPid);
  106.  
  107.         if( !c ) return CP_TRANSPORT_BUSY;
  108.  
  109.         if( CPid->sip != TRUE ) return CP_NO_SESSION_IN_PROGRESS;
  110.  
  111.         c->cpmsg.cphdr = CPid->cphdr;
  112.         memmove(c->cpmsg.msg,data,min(CPMAXMSG,length));
  113.     #if defined(DOSCLIENT) || defined(WINCLIENT)
  114.         IPXGetLocalTarget((BYTE *)c->ipx.destination.network,
  115.                           c->ecb.immediateAddress, &tTime);
  116.     #elif defined(NLMCLIENT)
  117.         IpxGetLocalTarget((char *)&c->ipx.destNet, &c->ecb, (LONG *)&tTime);
  118.     #endif
  119.         IPXSend(&c->ecb);
  120.         //
  121.         //  wait tTime for the packet to get onto the wire.
  122.         //
  123.         startTicks = IPXGetIntervalMarker();    // read start time
  124.         while( ECBISINUSE(&c->ecb) ){
  125.             IPXRelinquishControl();
  126.             endTicks = IPXGetIntervalMarker();
  127.             //
  128.             //  Give it enough time to get there. Shouldn't take this
  129.             //  long to get it out on the wire...
  130.             //
  131.             if( endTicks - startTicks > tTime ) break;
  132.         }
  133.         xDIAG4(CPprintf(ECBISINUSE(&c->ecb) ? "returning with inuseflag set on send\n" : ""));
  134.         return (ECBISINUSE(&c->ecb) || COMPLETIONCODE(&c->ecb)) 
  135.                 ? CP_TRANSPORT_ERROR 
  136.                 : CP_SUCCESS;
  137. }
  138.  
  139. #pragma off(unreferenced);
  140. void    CPDeInitializeSendLogic(CPDATA *CPid)
  141. #pragma on(unreferenced);
  142. {
  143.         int     i;
  144.         //
  145.         //  Wait for the send ECBs to finish sending.
  146.         //
  147.         for(i=0; i < CPCNUMSENDECBS; ++i){
  148.             while( ECBISINUSE(&CPid->sends[i].ecb) )
  149.                 IPXRelinquishControl();
  150.         }
  151. }
  152.