home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / netds / rpc / mandel / server.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-06-11  |  4.0 KB  |  130 lines

  1. /****************************************************************************
  2.                    Microsoft RPC Version 2.0
  3.            Copyright Microsoft Corp. 1992, 1993, 1994- 1996
  4.                          mandel Example
  5.  
  6.     FILE:       server.c
  7.  
  8.     USAGE:      server  -p protocol_sequence
  9.                         -e endpoint
  10.                         -m max calls
  11.                         -n min calls
  12.                         -f flag for RpcServerListen
  13.  
  14.     PURPOSE:    Server side of RPC distributed application mandel
  15.  
  16.     FUNCTIONS:  main() - registers interface and listen for clients
  17.  
  18. ****************************************************************************/
  19.  
  20. #include <stdlib.h>
  21. #include <stdio.h>
  22. #include <ctype.h>
  23. #include "mdlrpc.h"    // header file generated by MIDL compiler
  24.  
  25.  
  26. void Usage(char * pszProgramName)
  27. {
  28.     fprintf(stderr, "Usage:  %s\n", pszProgramName);
  29.     fprintf(stderr, " -p protocol_sequence\n");
  30.     fprintf(stderr, " -e endpoint\n");
  31.     fprintf(stderr, " -m maxcalls\n");
  32.     fprintf(stderr, " -n mincalls\n");
  33.     fprintf(stderr, " -f flag_wait_op\n");
  34.     exit(1);
  35. }
  36.  
  37. void _CRTAPI1 main(int argc, char * argv[])
  38. {
  39.     RPC_STATUS status;
  40.     unsigned char * pszProtocolSequence = "ncacn_np";
  41.     unsigned char * pszSecurity         = NULL;
  42.     unsigned char * pszEndpoint         = "\\pipe\\mandel";
  43.     unsigned int    cMinCalls           = 1;
  44.     unsigned int    cMaxCalls           = 20;
  45.     unsigned int    fDontWait           = FALSE;
  46.     int i;
  47.  
  48.     /* allow the user to override settings with command line switches */
  49.     for (i = 1; i < argc; i++) {
  50.         if ((*argv[i] == '-') || (*argv[i] == '/')) {
  51.             switch (tolower(*(argv[i]+1))) {
  52.             case 'p':  // protocol sequence
  53.                 pszProtocolSequence = argv[++i];
  54.                 break;
  55.             case 'e':
  56.                 pszEndpoint = argv[++i];
  57.                 break;
  58.             case 'm':
  59.                 cMaxCalls = (unsigned int) atoi(argv[++i]);
  60.                 break;
  61.             case 'n':
  62.                 cMinCalls = (unsigned int) atoi(argv[++i]);
  63.                 break;
  64.             case 'f':
  65.                 fDontWait = (unsigned int) atoi(argv[++i]);
  66.                 break;
  67.             case 'h':
  68.             case '?':
  69.             default:
  70.                 Usage(argv[0]);
  71.             }
  72.         }
  73.         else
  74.             Usage(argv[0]);
  75.     }
  76.  
  77.     status = RpcServerUseProtseqEp(pszProtocolSequence,
  78.                                    cMaxCalls,
  79.                                    pszEndpoint,
  80.                                    pszSecurity);  // Security descriptor
  81.     printf("RpcServerUseProtseqEp returned 0x%x\n", status);
  82.     if (status) {
  83.         exit(status);
  84.     }
  85.  
  86.     status = RpcServerRegisterIf(mdlrpc_ServerIfHandle, // interface to register
  87.                                  NULL,   // MgrTypeUuid
  88.                                  NULL);  // MgrEpv; null means use default
  89.     printf("RpcServerRegisterIf returned 0x%x\n", status);
  90.     if (status) {
  91.         exit(status);
  92.     }
  93.  
  94.     printf("Calling RpcServerListen\n");
  95.     status = RpcServerListen(cMinCalls,
  96.                              cMaxCalls,
  97.                              fDontWait);
  98.     printf("RpcServerListen returned: 0x%x\n", status);
  99.     if (status) {
  100.         exit(status);
  101.     }
  102.  
  103.     if (fDontWait) {
  104.         printf("Calling RpcMgmtWaitServerListen\n");
  105.         status = RpcMgmtWaitServerListen();  //  wait operation
  106.         printf("RpcMgmtWaitServerListen returned: 0x%x\n", status);
  107.         if (status) {
  108.             exit(status);
  109.         }
  110.     }
  111.  
  112. } // end main()
  113.  
  114.  
  115. /*********************************************************************/
  116. /*                MIDL allocate and free                             */
  117. /*********************************************************************/
  118.  
  119. void __RPC_FAR * __RPC_API midl_user_allocate(size_t len)
  120. {
  121.     return(malloc(len));
  122. }
  123.  
  124. void __RPC_API midl_user_free(void __RPC_FAR * ptr)
  125. {
  126.     free(ptr);
  127. }
  128.  
  129. /* end server.c */
  130.