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 / msendrcv.h < prev    next >
Text File  |  1997-04-09  |  11KB  |  227 lines

  1. /* msendrcv.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_SEND_PER_THREAD 64
  17. #define MAX_RCV_PER_THREAD  63
  18. #define MAX_RECEIVE_THREADS 64
  19. #define MAXRCVBUF 4096
  20.  
  21. /*****************************************************************************/
  22. /* global critical section                                                   */
  23. /*****************************************************************************/
  24. CRITICAL_SECTION runsem;
  25.  
  26. /*****************************************************************************/
  27. /* APPC verb control block and macros for manipulation of vcb                */
  28. /*****************************************************************************/
  29. #define CLEARVCB memset(vcbptr,0,sizeof(VCB));
  30. #define P_TPS(X)    ((struct tp_started *)X)
  31. #define P_TPE(X)    ((struct tp_ended *)X)
  32. #define P_RAL(X)    ((struct receive_allocate *)X)
  33.  
  34. #define P_M_ALC(X)  ((struct mc_allocate *)X)
  35. #define P_M_CNF(X)  ((struct mc_confirm *)X)
  36. #define P_M_CFD(X)  ((struct mc_confirmed *)X)
  37. #define P_M_DAL(X)  ((struct mc_deallocate *)X)
  38. #define P_M_RAW(X)  ((struct mc_receive_and_wait *)X)
  39. #define P_M_SDD(X)  ((struct mc_send_data *)X)
  40.  
  41. typedef struct vcb
  42. {
  43.   union
  44.   {
  45.     struct appc_hdr             hdr;
  46.     struct receive_allocate     rcvalloc;
  47.     struct tp_started           tpstart;
  48.     struct tp_ended             tpend;
  49.     struct mc_allocate          allocate;
  50.     struct mc_confirm           confirm;
  51.     struct mc_confirmed         confirmed;
  52.     struct mc_deallocate        deallocate;
  53.     struct mc_receive_and_wait  rcvwait;
  54.     struct mc_send_data         snddata;
  55.   } U_VCB;
  56. } VCB;
  57.  
  58. /*****************************************************************************/
  59. /* structures for convert verb                                               */
  60. /*****************************************************************************/
  61. struct convert cnvt;
  62. char * cnvtptr;
  63.  
  64. /*****************************************************************************/
  65. /* for outputting results                                                    */
  66. /*****************************************************************************/
  67. typedef unsigned long RESULT;
  68. RESULT * ResultPtr;
  69. RESULT * ResultBuf;
  70. short    NumResults;
  71.  
  72. /*****************************************************************************/
  73. /* conversation control block - one per conversation                         */
  74. /*****************************************************************************/
  75. typedef struct convcb
  76. {
  77.   char           TPid[8];
  78.   char           type[8];
  79.   unsigned long  Convid;
  80.   HANDLE         async_corr;
  81.   char *         DataPtr;
  82.   unsigned short thread;
  83.   unsigned short conv;
  84.   unsigned short SendSize;
  85.   unsigned short SendCount;
  86.   unsigned short RcvCount;
  87.   unsigned short ConfirmCount;
  88.   BOOL           TPEnded;
  89.   BOOL           Deallocated;
  90.   BOOL           Counted;
  91.   RESULT         ConvStarted;
  92.   HANDLE         hEvent;
  93.   VCB            vcb;
  94. } CONVCB;
  95.  
  96. /*****************************************************************************/
  97. /* structures for receive threads                                            */
  98. /*****************************************************************************/
  99. typedef struct rcv_thread
  100. {
  101.   HANDLE event1;
  102.   HANDLE event2;
  103.   CONVCB * convptr;
  104. } RCV_THREAD;
  105.  
  106. RCV_THREAD RcvThreadArray [MAX_RECEIVE_THREADS];
  107.  
  108. /*****************************************************************************/
  109. /* File Names and handle for trace file                                      */
  110. /*****************************************************************************/
  111. char FileName [60];
  112. char TraceFile[60];
  113. FILE *t = NULL;
  114.  
  115. /*****************************************************************************/
  116. /* APPC Names from configuration file                                        */
  117. /*****************************************************************************/
  118. char TPName[64];
  119. char LocalTPName[64];
  120. char LocalLUAlias[8];
  121. char RemoteLUAlias[8];
  122. char ModeName[8];
  123. char RemoteTPName[64];
  124.  
  125. /*****************************************************************************/
  126. /* Global Variables from configuration file                                  */
  127. /*****************************************************************************/
  128. unsigned short NumSends;
  129. unsigned short SendSize;
  130. unsigned short NumSendConvs;
  131. unsigned short ConfirmEvery;
  132. unsigned short NumRcvThreads;
  133. unsigned short NumRcvConvs;
  134. unsigned short RcvSize;
  135.  
  136. /*****************************************************************************/
  137. /* Global Variables                                                          */
  138. /*****************************************************************************/
  139. unsigned short NumRalcs;                /* number of receive_allocs issued   */
  140. unsigned short RcvConvs;                /* number of conversations completed */
  141. unsigned short ThreadCount;             /* total thread count                */
  142. unsigned short RcvThreads;              /* count of receive threads          */
  143. unsigned short SendThreads;             /* count of send threads             */
  144. unsigned short SimRcvConvs;             /* number of simultaneous rcv convs  */
  145. unsigned short SimSendConvs;            /* number of simultaneous send convs */
  146.  
  147. /*****************************************************************************/
  148. /* Names of verbs for tracing                                                */
  149. /*****************************************************************************/
  150. char *VerbName[] =
  151. {
  152.   "UNKNOWN_VERB",                       /* 0x0000                            */
  153.   "MC_ALLOCATE",                        /* 0x0001                            */
  154.   "UNKNOWN_VERB",                       /* 0x0002                            */
  155.   "MC_CONFIRM",                         /* 0x0003                            */
  156.   "MC_CONFIRMED",                       /* 0x0004                            */
  157.   "MC_DEALLOCATE",                      /* 0x0005                            */
  158.   "MC_FLUSH",                           /* 0x0006                            */
  159.   "MC_GET_ATTRIBUTES",                  /* 0x0007                            */
  160.   "UNKNOWN_VERB",                       /* 0x0008                            */
  161.   "UNKNOWN_VERB",                       /* 0x0009                            */
  162.   "MC_PREPARE_TO_RECEIVE",              /* 0x000a                            */
  163.   "MC_RECEIVE_AND_WAIT",                /* 0x000b                            */
  164.   "MC_RECEIVE_IMMEDIATE",               /* 0x000c                            */
  165.   "MC_RECEIVE_AND_POST",                /* 0x000d                            */
  166.   "MC_REQUEST_TO_SEND",                 /* 0x000e                            */
  167.   "MC_SEND_DATA",                       /* 0x000f                            */
  168.   "MC_SEND_ERROR",                      /* 0x0010                            */
  169.   "UNKNOWN_VERB",                       /* 0x0011                            */
  170.   "MC_TEST_RTS",                        /* 0x0012                            */
  171.   "TP_ENDED",                           /* 0x0013                            */
  172.   "TP_STARTED",                         /* 0x0014                            */
  173.   "UNKNOWN_VERB",                       /* 0x0015                            */
  174.   "RECEIVE_ALLOCATE",                   /* 0x0016                            */
  175.   "UNKNOWN_VERB",                       /* 0x0017                            */
  176.   "MC_SEND_CONVERSATION"                /* 0x0018                            */
  177. };
  178.  
  179. /*****************************************************************************/
  180. /* Character for filling buffer                                              */
  181. /*****************************************************************************/
  182. char datach;
  183.  
  184. /*****************************************************************************/
  185. /* Windows stuff                                                             */
  186. /*****************************************************************************/
  187. HWND hWndMain;
  188. char title[40]={'\0'};
  189. #define OUTPUTNUMBER sprintf(title,"thr sms smr rdn  %d  %d  %d  %d", \
  190.                      ThreadCount,SimSendConvs,SimRcvConvs,RcvConvs);  \
  191.                      SetWindowText(hWndMain,title);
  192.  
  193. /*****************************************************************************/
  194. /* Function Prototypes                                                       */
  195. /*****************************************************************************/
  196. int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
  197.                    LPSTR lpCmdLine, int nCmdShow);
  198. BOOL InitializeWinMain(HINSTANCE hInstance);
  199. LONG PASCAL TPWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
  200. void InitializeMain(void);
  201. BOOL IssueSendVerb(CONVCB * convptr);
  202. BOOL IssueRcvVerb(CONVCB * convptr);
  203. BOOL ProcessReturns(CONVCB * convptr);
  204. void ReadConfig(void);
  205. void CONV_A_TO_E(char * string,int length);
  206. void CONV_E_TO_A(char * string,int length);
  207. void StartConversation(CONVCB * convptr);
  208. void EndConversation(CONVCB * convptr);
  209. int  ReadString(char * lpValueName, char FAR * lpData, int maxlen);
  210. void PadString(char * string, int length);
  211. void OutputResults(void);
  212. void Build_RECEIVE_ALLOCATE(CONVCB * convptr);
  213. void Build_TP_STARTED(CONVCB * convptr);
  214. void Build_TP_ENDED(CONVCB * convptr);
  215. void Build_MC_ALLOCATE(CONVCB * convptr);
  216. void Build_MC_CONFIRM(CONVCB * convptr);
  217. void Build_MC_CONFIRMED(CONVCB * convptr);
  218. void Build_MC_DEALLOCATE(CONVCB * convptr);
  219. void Build_MC_RECEIVE_AND_WAIT(CONVCB * convptr);
  220. void Build_MC_SEND_CONVERSATION(CONVCB * convptr);
  221. void Build_MC_SEND_DATA(CONVCB * convptr);
  222. void GenerateData(CONVCB * convptr);
  223. DWORD WINAPI RcvAllocThread();
  224. DWORD WINAPI ReceiveThread(DWORD k);
  225. DWORD WINAPI SendThread(DWORD k);
  226.  
  227.