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 / data / xmit / xmits.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-06-11  |  4.9 KB  |  140 lines

  1. /****************************************************************************
  2.                    Microsoft RPC Version 2.0
  3.            Copyright Microsoft Corp. 1992, 1993, 1994- 1996
  4.                         xmit Example
  5.  
  6.     FILE:       xmits.c
  7.  
  8.     USAGE:      xmits  -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 xmit
  15.  
  16.     FUNCTIONS:  main() - registers server as RPC server
  17.  
  18.     COMMENTS:   This sample program generates a linked list to
  19.                 demonstrate how the list can be transmitted over
  20.                 the network more efficiently as a sized array.
  21.                 The pointers are rebuilt on the server side.
  22.  
  23.                 The [transmit_as] attribute (used in the typedef of
  24.                 DOUBLE_LINK_TYPE in the file XMIT.IDL) requires the
  25.                 four user-supplied functions whose names start with
  26.                 the name of the presented type, DOUBLE_LINK_TYPE.
  27.  
  28.                 The [in, out] attributes applied to remote procedure
  29.                 parameters require the two user-supplied functions
  30.                 midl_user_allocate and midl_user_free.
  31.  
  32.                 The other functions are utilities that are used to
  33.                 build or display the data structures.
  34.  
  35. ****************************************************************************/
  36.  
  37. #include <stdlib.h>
  38. #include <stdio.h>
  39. #include <ctype.h>
  40. #include "xmit.h"     // header file generated by MIDL compiler
  41. #include "xmitu.h"    // Function prototypes for utility functions
  42.  
  43. #define PURPOSE \
  44. "This Microsoft RPC Version 2.0 sample program demonstrates\n\
  45. the use of the [transmit_as] attribute. For more information\n\
  46. about the attributes and the RPC API functions, see the\n\
  47. RPC programming guide and reference.\n\n"
  48.  
  49. void Usage(char * pszProgramName)
  50. {
  51.     fprintf(stderr, "%s", PURPOSE);
  52.     fprintf(stderr, "Usage:  %s\n", pszProgramName);
  53.     fprintf(stderr, " -p protocol_sequence\n");
  54.     fprintf(stderr, " -e endpoint\n");
  55.     fprintf(stderr, " -m maxcalls\n");
  56.     fprintf(stderr, " -n mincalls\n");
  57.     fprintf(stderr, " -f flag_wait_op\n");
  58.     exit(1);
  59. }
  60.  
  61. /* main:  register the interface, start listening for clients */
  62. void _CRTAPI1 main(int argc, char * argv[])
  63. {
  64.     RPC_STATUS status;
  65.     unsigned char * pszProtocolSequence = "ncacn_np";
  66.     unsigned char * pszSecurity         = NULL;
  67.     unsigned char * pszEndpoint         = "\\pipe\\xmit";
  68.     unsigned int    cMinCalls           = 1;
  69.     unsigned int    cMaxCalls           = 20;
  70.     unsigned int    fDontWait           = FALSE;
  71.     int i;
  72.  
  73.     /* allow the user to override settings with command line switches */
  74.     for (i = 1; i < argc; i++) {
  75.         if ((*argv[i] == '-') || (*argv[i] == '/')) {
  76.             switch (tolower(*(argv[i]+1))) {
  77.             case 'p':  // protocol sequence
  78.                 pszProtocolSequence = argv[++i];
  79.                 break;
  80.             case 'e':
  81.                 pszEndpoint = argv[++i];
  82.                 break;
  83.             case 'm':
  84.                 cMaxCalls = (unsigned int) atoi(argv[++i]);
  85.                 break;
  86.             case 'n':
  87.                 cMinCalls = (unsigned int) atoi(argv[++i]);
  88.                 break;
  89.             case 'f':
  90.                 fDontWait = (unsigned int) atoi(argv[++i]);
  91.                 break;
  92.             case 'h':
  93.             case '?':
  94.             default:
  95.                 Usage(argv[0]);
  96.             }
  97.         }
  98.         else
  99.             Usage(argv[0]);
  100.     }
  101.  
  102.     status = RpcServerUseProtseqEp(pszProtocolSequence,
  103.                                    cMaxCalls,
  104.                                    pszEndpoint,
  105.                                    pszSecurity);  // Security descriptor
  106.     printf("RpcServerUseProtseqEp returned 0x%x\n", status);
  107.     if (status) {
  108.         exit(status);
  109.     }
  110.  
  111.     status = RpcServerRegisterIf(xmit_ServerIfHandle,  // interface to register
  112.                                  NULL,   // MgrTypeUuid
  113.                                  NULL);  // MgrEpv; null means use default
  114.     printf("RpcServerRegisterIf returned 0x%x\n", status);
  115.     if (status) {
  116.         exit(status);
  117.     }
  118.  
  119.     printf("Calling RpcServerListen\n");
  120.     status = RpcServerListen(cMinCalls,
  121.                              cMaxCalls,
  122.                              fDontWait);
  123.     printf("RpcServerListen returned: 0x%x\n", status);
  124.     if (status) {
  125.         exit(status);
  126.     }
  127.  
  128.     if (fDontWait) {
  129.         printf("Calling RpcMgmtWaitServerListen\n");
  130.         status = RpcMgmtWaitServerListen();  //  wait operation
  131.         printf("RpcMgmtWaitServerListen returned: 0x%x\n", status);
  132.         if (status) {
  133.             exit(status);
  134.         }
  135.     }
  136.  
  137. }  // end main()
  138.  
  139. /* end file xmits.c */
  140.