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

  1. //   ╔════════════════════════════════════════════════════════════════════╗
  2. //   ║                                                                    ║
  3. //   ║ module:      cprecv.c                                              ║
  4. //   ║ abstract:    This module contains the APIs to receive messages     ║
  5. //   ║              from the application server.                          ║
  6. //   ║                                                                    ║
  7. //   ║ environment: NetWare 3.x v3.11                                     ║
  8. //   ║              Network C for NLMs SDK v2.0d                          ║
  9. //   ║              CLib v3.11                                            ║
  10. //   ║              Network C for DOS v2.0                                ║
  11. //   ║              NetWare C Interface DOS v1.2                          ║
  12. //   ║                                                                    ║
  13. //   ║  This software is provided as is and carries no warranty           ║
  14. //   ║  whatsoever.  Novell disclaims and excludes any and all implied    ║
  15. //   ║  warranties of merchantability, title and fitness for a particular ║
  16. //   ║  purpose.  Novell does not warrant that the software will satisfy  ║
  17. //   ║  your requirements or that the software is without defect or error ║
  18. //   ║  or that operation of the software will be uninterrupted.  You are ║
  19. //   ║  using the software at your risk.  The software is not a product   ║
  20. //   ║  of Novell, Inc. or any of subsidiaries.                           ║
  21. //   ║                                                                    ║
  22. //   ╟────────────────────────────────────────────────────────────────────╢
  23. //   ║ maintenance history:                                               ║
  24. //   ║ level    date      pi   description                                ║
  25. //   ╟────────────────────────────────────────────────────────────────────╢
  26. //   ║  001   01/24/92    kl   initial release.                           ║
  27. //   ║  002   07/14/92    kl   windows port.                              ║
  28. //   ╚════════════════════════════════════════════════════════════════════╝
  29.  
  30. #include <stdio.h>
  31. #include <stdlib.h>
  32. #include <string.h>
  33. #include "cp/cpsys.h"
  34.  
  35. void    CPInitRecvPacket(WORD      socket, 
  36.                          ECB       *ecb, 
  37.                          IPXHeader *packet,
  38.                          void      *reply, 
  39.                          WORD      replySize)
  40. {
  41.         ECBSOCKET(ecb)     = socket;
  42.         ECBFRAGCOUNT(ecb)  = 2;
  43.         ECBFRAGADDR(ecb,0) = packet;
  44.         ECBFRAGSIZE(ecb,0) = sizeof(IPXHeader);
  45.         ECBFRAGADDR(ecb,1) = reply;
  46.         ECBFRAGSIZE(ecb,1) = replySize;
  47. }
  48.  
  49. T_RC    CPInitializeRecvLogic(CPDATA *CPid)
  50. {
  51.         int     i;
  52.         //
  53.         //  Get two recv ECBs ready.  One for receiving requests, and one
  54.         //  for receiving replies.
  55.         //
  56.         for(i=0; i < CPCNUMRECVECBS; ++i){
  57.             CPInitRecvPacket(CPid->skt,
  58.                              &CPid->recvs[i].ecb,
  59.                              &CPid->recvs[i].ipx,
  60.                              &CPid->recvs[i].cpmsg,
  61.                              sizeof CPid->recvs[i].cpmsg);
  62.             IPXReceive(&CPid->recvs[i].ecb);
  63.         }
  64.         return CP_SUCCESS;
  65. }
  66. #if 0
  67. //
  68. //!! remove this prototype from header file, not needed any longer...
  69. //
  70. void    CPRepostAnyCompletedECBs(CPDATA *CPid)
  71. {
  72.         int     i;
  73.  
  74.         for(i=0; i < CPCNUMRECVECBS; ++i){
  75.             if( !ECBISINUSE(&CPid->recvs[i].ecb) ){
  76.                 //
  77.                 //  Return this ECB to the listening pool
  78.                 //
  79.                 DIAG3("CPRepostECBs() detected completed ECB!");
  80.                 IPXReceive(&CPid->recvs[i].ecb);
  81.             }
  82.         }
  83. }
  84. #endif
  85. T_RC    CPRecvMessage(CPDATA *CPid, void *recbuf, unsigned length)
  86. {
  87.         int     i;
  88.  
  89.         for(i=0; i < CPCNUMRECVECBS; ++i){
  90.             if( !ECBISINUSE(&CPid->recvs[i].ecb) ){
  91.                 //
  92.                 //  If an error occured on the receive, just return.  Don't
  93.                 //  even bother to repost the ECB.  Should put in a more
  94.                 //  intelligent error handler here, as some errors can be
  95.                 //  handled without just giving up like this...
  96.                 //
  97.                 if( COMPLETIONCODE(&CPid->recvs[i].ecb) ) return CP_TRANSPORT_ERROR;
  98.                 //
  99.                 //  Save the header info from the CP Layer on the server
  100.                 //  side.  This keeps us in sync with the server side.
  101.                 //  Verify that the CP signature on the packet header is valid!
  102.                 //
  103.                 if( CPid->recvs[i].cpmsg.cphdr.signature != CPPKTSIG ) return CP_TRANSPORT_ERROR;
  104.                 //
  105.                 //  Save the cphdr for next time
  106.                 //
  107.                 CPid->cphdr = CPid->recvs[i].cpmsg.cphdr;
  108.                 HEXDIAG4("CP Layer session id is ",CPid->cphdr.serverID);
  109.                 //
  110.                 //  Transfer the received data to the user buffer.
  111.                 //
  112.                 memmove(recbuf,CPid->recvs[i].cpmsg.msg,min(CPMAXMSG,length));
  113.                 //
  114.                 //  Return this ECB to the listening pool
  115.                 //
  116.                 IPXReceive(&CPid->recvs[i].ecb);
  117.                 //
  118.                 //  Return success to the caller.  i.e. we got something.
  119.                 //
  120.                 return CP_SUCCESS;
  121.             }
  122.         }
  123.         return CP_NO_MESSAGE;
  124. }
  125.  
  126. #pragma off(unreferenced);
  127. void    CPDeInitializeRecvLogic(CPDATA *CPid)
  128. #pragma on(unreferenced);
  129. {
  130.         int     i;
  131.         //
  132.         //  If any ECBs are still active, go ahead and cancel them.
  133.         //
  134.         for(i=0; i < CPCNUMRECVECBS; ++i)
  135.             if( ECBISINUSE(&CPid->recvs[i].ecb) )
  136.                 IPXCancelEvent(&CPid->recvs[i].ecb);
  137. }
  138.