home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / netds / sna / msendrcv / mrcv.h < prev    next >
Text File  |  1997-04-09  |  9KB  |  194 lines

  1. /* mrcv.h */
  2. /* (C) COPYRIGHT DATA CONNECTION LIMITED 1994 */
  3.  
  4. /*****************************************************************************/
  5. /* Change History                                                            */
  6. /*                                                                           */
  7. /*       11/01/94 DK  Created                                                */
  8. /*       14/04/94 DK  Name table added for tracing                           */
  9. /*****************************************************************************/
  10.  
  11. /*****************************************************************************/
  12. /* static configuration constants                                            */
  13. /* Note that MAX_RCV_PER_SERVICE cannot exceed 63, because we cannot wait    */
  14. /*      on more than 64 events (and one extra event is needed for receive)   */
  15. /*****************************************************************************/
  16. #define MAX_RCV_PER_THREAD  63
  17. #define MAX_RECEIVE_THREADS 64
  18.  
  19. /*****************************************************************************/
  20. /* global critical section                                                   */
  21. /*****************************************************************************/
  22. CRITICAL_SECTION runsem;
  23.  
  24. /*****************************************************************************/
  25. /* APPC verb control block and macros for manipulation of vcb                */
  26. /*****************************************************************************/
  27. #define CLEARVCB memset(vcbptr,0,sizeof(VCB));
  28. #define P_TPE(X)    ((struct tp_ended *)X)
  29. #define P_RAL(X)    ((struct receive_allocate *)X)
  30.  
  31. #define P_M_CFD(X)  ((struct mc_confirmed *)X)
  32. #define P_M_DAL(X)  ((struct mc_deallocate *)X)
  33. #define P_M_RAW(X)  ((struct mc_receive_and_wait *)X)
  34.  
  35. typedef struct vcb
  36. {
  37.   union
  38.   {
  39.     struct appc_hdr             hdr;
  40.     struct receive_allocate     rcvalloc;
  41.     struct tp_ended             tpend;
  42.     struct mc_confirmed         confirmed;
  43.     struct mc_deallocate        deallocate;
  44.     struct mc_receive_and_wait  rcvwait;
  45.   } U_VCB;
  46. } VCB;
  47.  
  48. /*****************************************************************************/
  49. /* structures for convert verb                                               */
  50. /*****************************************************************************/
  51. struct convert cnvt;
  52. char * cnvtptr;
  53.  
  54. /*****************************************************************************/
  55. /* for outputting results                                                    */
  56. /*****************************************************************************/
  57. typedef unsigned long RESULT;
  58. RESULT * ResultPtr;
  59. RESULT * ResultBuf;
  60. short    NumResults;
  61.  
  62. /*****************************************************************************/
  63. /* conversation control block - one per conversation                         */
  64. /*****************************************************************************/
  65. typedef struct convcb
  66. {
  67.   char           TPid[8];
  68.   char           type[8];
  69.   unsigned long  Convid;
  70.   HANDLE         async_corr;
  71.   char *         DataPtr;
  72.   unsigned short thread;
  73.   unsigned short conv;
  74.   unsigned short RcvCount;
  75.   BOOL           TPEnded;
  76.   BOOL           Deallocated;
  77.   RESULT         ConvStarted;
  78.   HANDLE         hEvent;
  79.   VCB            vcb;
  80. } CONVCB;
  81.  
  82. /*****************************************************************************/
  83. /* structures for receive threads                                            */
  84. /*****************************************************************************/
  85. typedef struct rcv_thread
  86. {
  87.   HANDLE event1;
  88.   HANDLE event2;
  89.   CONVCB * convptr;
  90. } RCV_THREAD;
  91.  
  92. RCV_THREAD RcvThreadArray [MAX_RECEIVE_THREADS];
  93.  
  94. /*****************************************************************************/
  95. /* File Names and handle for trace file                                      */
  96. /*****************************************************************************/
  97. char FileName [60];
  98. char TraceFile[60];
  99. FILE *t = NULL;
  100.  
  101. /*****************************************************************************/
  102. /* APPC Names from configuration file                                        */
  103. /*****************************************************************************/
  104. char TPName[64];
  105. char LocalTPName[64];
  106. char LocalLUAlias[8];
  107. char RemoteLUAlias[8];
  108. char ModeName[8];
  109. char RemoteTPName[64];
  110.  
  111. /*****************************************************************************/
  112. /* Global Variables from configuration file                                  */
  113. /*****************************************************************************/
  114. unsigned short NumRcvThreads;
  115. unsigned short NumRcvConvs;
  116. unsigned short RcvSize;
  117.  
  118. /*****************************************************************************/
  119. /* Global Variables                                                          */
  120. /*****************************************************************************/
  121. unsigned short NumRalcs;                /* number of receive_allocs issued   */
  122. unsigned short RcvConvs;                /* number of conversations completed */
  123. unsigned short ThreadCount;             /* total thread count                */
  124. unsigned short RcvThreads;              /* count of receive threads          */
  125. unsigned short SimRcvConvs;             /* number of simultaneous rcv convs  */
  126.  
  127. /*****************************************************************************/
  128. /* Names of verbs for tracing                                                */
  129. /*****************************************************************************/
  130. char *VerbName[] =
  131. {
  132.   "UNKNOWN_VERB",                       /* 0x0000                            */
  133.   "MC_ALLOCATE",                        /* 0x0001                            */
  134.   "UNKNOWN_VERB",                       /* 0x0002                            */
  135.   "MC_CONFIRM",                         /* 0x0003                            */
  136.   "MC_CONFIRMED",                       /* 0x0004                            */
  137.   "MC_DEALLOCATE",                      /* 0x0005                            */
  138.   "MC_FLUSH",                           /* 0x0006                            */
  139.   "MC_GET_ATTRIBUTES",                  /* 0x0007                            */
  140.   "UNKNOWN_VERB",                       /* 0x0008                            */
  141.   "UNKNOWN_VERB",                       /* 0x0009                            */
  142.   "MC_PREPARE_TO_RECEIVE",              /* 0x000a                            */
  143.   "MC_RECEIVE_AND_WAIT",                /* 0x000b                            */
  144.   "MC_RECEIVE_IMMEDIATE",               /* 0x000c                            */
  145.   "MC_RECEIVE_AND_POST",                /* 0x000d                            */
  146.   "MC_REQUEST_TO_SEND",                 /* 0x000e                            */
  147.   "MC_SEND_DATA",                       /* 0x000f                            */
  148.   "MC_SEND_ERROR",                      /* 0x0010                            */
  149.   "UNKNOWN_VERB",                       /* 0x0011                            */
  150.   "MC_TEST_RTS",                        /* 0x0012                            */
  151.   "TP_ENDED",                           /* 0x0013                            */
  152.   "TP_STARTED",                         /* 0x0014                            */
  153.   "UNKNOWN_VERB",                       /* 0x0015                            */
  154.   "RECEIVE_ALLOCATE",                   /* 0x0016                            */
  155.   "UNKNOWN_VERB",                       /* 0x0017                            */
  156.   "MC_SEND_CONVERSATION"                /* 0x0018                            */
  157. };
  158.  
  159. /*****************************************************************************/
  160. /* Windows stuff                                                             */
  161. /*****************************************************************************/
  162. HWND hWndMain;
  163. char title[30]={'\0'};
  164. #define OUTPUTNUMBER sprintf(title,"thrd simR done  %d  %d  %d", \
  165.                      ThreadCount,SimRcvConvs,RcvConvs);  \
  166.                      SetWindowText(hWndMain,title);
  167.  
  168. /*****************************************************************************/
  169. /* Function Prototypes                                                       */
  170. /*****************************************************************************/
  171. int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
  172.                    LPSTR lpCmdLine, int nCmdShow);
  173. BOOL InitializeWinMain(HINSTANCE hInstance);
  174. LONG PASCAL TPWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
  175. void InitializeMain(void);
  176. BOOL IssueRcvVerb(CONVCB * convptr);
  177. BOOL ProcessReturns(CONVCB * convptr);
  178. void ReadConfig(void);
  179. void CONV_A_TO_E(char * string,int length);
  180. void CONV_E_TO_A(char * string,int length);
  181. void StartConversation(CONVCB * convptr);
  182. void EndConversation(CONVCB * convptr);
  183. int  ReadString(char * lpValueName, char FAR * lpData, int maxlen);
  184. void PadString(char * string, int length);
  185. void OutputResults(void);
  186. void Build_RECEIVE_ALLOCATE(CONVCB * convptr);
  187. void Build_TP_ENDED(CONVCB * convptr);
  188. void Build_MC_CONFIRMED(CONVCB * convptr);
  189. void Build_MC_DEALLOCATE(CONVCB * convptr);
  190. void Build_MC_RECEIVE_AND_WAIT(CONVCB * convptr);
  191. DWORD WINAPI RcvAllocThread();
  192. DWORD WINAPI ReceiveThread(DWORD k);
  193.  
  194.