home *** CD-ROM | disk | FTP | other *** search
/ Network Support Encyclopedia 96-1 / novell-nsepro-1996-1-cd2.iso / download / netware / dax1.exe / CLIENT / INOUT / NLM / INOUT.C next >
Text File  |  1992-07-15  |  5KB  |  147 lines

  1. //   ╔════════════════════════════════════════════════════════════════════╗
  2. //   ║                                                                    ║
  3. //   ║ module:      inout.c                                               ║
  4. //   ║ abstract:    This module logs in and out of the DAP Engine.        ║
  5. //   ║              This NLM version can spawn multiple clients, threads, ║
  6. //   ║              which can really test 'race' conditions.              ║
  7. //   ║                                                                    ║
  8. //   ║ environment: NetWare 3.x v3.11                                     ║
  9. //   ║              Network C for NLMs SDK                                ║
  10. //   ║              CLib v3.11                                            ║
  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   03/05/92    kl   initial release.                           ║
  26. //   ╚════════════════════════════════════════════════════════════════════╝
  27.  
  28. #include <stdio.h>
  29. #include <conio.h>
  30. #include <stdlib.h>
  31. #include <string.h>
  32. #include <errno.h>
  33. #include <nwsemaph.h>
  34.  
  35. #include "h/appl.h"
  36. #include "dap/dapapi.h"
  37.  
  38. LONG    semaIOHandle;
  39.  
  40. myprintf(int threadnum, int offset, char *msg)
  41. {
  42.         if( semaIOHandle ) WaitOnLocalSemaphore(semaIOHandle);
  43.         gotoxy((threadnum % 3) * 25 + offset, threadnum / 3);
  44.         while(*msg) putch(*msg++);
  45.         if( semaIOHandle ) SignalLocalSemaphore(semaIOHandle);
  46. }
  47.  
  48. threadputch(int threadnum, int offset, char byte)
  49. {
  50.         char    data[] = "?";
  51.         *data = byte;
  52.         myprintf(threadnum,offset,data);
  53. }
  54.  
  55. errorexit(int threadnum, int rc, char *msg, DAPDATA *dd)
  56. {
  57.     char    buf[255];
  58.  
  59.     sprintf(buf, "%s:%s",
  60.             msg,
  61.             DAPTranslateReturnCode(rc));
  62.     myprintf(threadnum, 0, buf);
  63.     if( dd ){
  64.         DAPDisplaySessionData(dd);
  65.         DAPDeInitialize(dd);
  66.     }
  67.     ExitThread(EXIT_THREAD,1);
  68. }
  69.  
  70. s_atexit()
  71. {
  72.         if( semaIOHandle ) CloseLocalSemaphore(semaIOHandle);
  73. }
  74.  
  75. #define threadAtSay(threadnum, msg)         myprintf(threadnum,0,msg)
  76. #define threadprint(threadnum,offset, msg)  myprintf(threadnum,offset,msg)
  77.  
  78. #define DEFOUTER    1000
  79. #define DEFINNER    10
  80. LONG    outerlimit = DEFOUTER;
  81. LONG    innerlimit = DEFINNER;
  82.  
  83. WorkerThread(void *_threadNum)
  84. {
  85.         int     rc,x,y;
  86.         int     offset;
  87.         LONG    iter=0L;
  88.         char    junk[10];
  89.         DAPDATA *dd;
  90.         int     threadNum = (int)_threadNum;
  91.  
  92.         for(x=0; !kbhit() && x < outerlimit; ++x){
  93.             for(y=1; !kbhit() && y < innerlimit; ++y){
  94.                 offset = 0;
  95.                 threadputch(threadNum, offset++,'i');
  96.                 if( (dd = DAPInitialize(SERVERNAME, SERVERTYPE)) == NULL ){
  97.                     threadAtSay(threadNum,"Could not initialize");
  98.                     ExitThread(EXIT_THREAD,1);
  99.                 }
  100.                 threadputch(threadNum, offset++,'a');
  101.                 if( (rc = DAPAllocateSession(dd)) != NULL ){
  102.                     errorexit(threadNum,rc,"AS",dd);
  103.                 }
  104.                 threadputch(threadNum, offset++,'d');
  105.                 sprintf(junk,"%04d",*(long *)&(((int *)dd)[1]));
  106.                 threadprint(threadNum,offset,junk);
  107.                 offset += 4;
  108.                 if( (rc = DAPDeAllocateSession(dd)) != NULL ){
  109.                     errorexit(threadNum,rc,"DA",dd);
  110.                 }
  111.                 threadputch(threadNum, offset++,'u');
  112.                 DAPDeInitialize(dd);
  113.                 threadprint(threadNum,0,"........");
  114.                 dd = NULL;
  115.                 ++iter;
  116.             }
  117.         }
  118.         ExitThread(EXIT_THREAD,0);
  119. }
  120.  
  121. main(int argc, char *argv[])
  122. {
  123.         int numclients;
  124.         int threadNum=0;
  125.  
  126.         if( argc < 2 ){
  127.             printf("usage: inout <numClients> [outer] [inner]\n");
  128.             exit(1);
  129.         }
  130.         atexit(s_atexit);
  131.         semaIOHandle = OpenLocalSemaphore(1);
  132.         numclients = atoi(argv[1]);
  133.         if( argc == 4 ){
  134.             outerlimit = atoi(argv[2]);
  135.             innerlimit = atoi(argv[3]);
  136.         }
  137.         while( numclients-- ){
  138.             if(BeginThreadGroup(WorkerThread,NULL,8192,(void *)threadNum) == EFAILURE){
  139.                 threadAtSay(threadNum,"Failed to start");
  140.                 exit(1);
  141.             }
  142.             threadNum++;
  143.             ThreadSwitch();
  144.         }
  145.         return 0;
  146. }
  147.