Annotation of mstools/samples/rpc/hello/hellos.c, revision 1.1.1.3

1.1       root        1: /****************************************************************************
1.1.1.3 ! root        2:               Microsoft RPC Version 1.0
        !             3:              Copyright Microsoft Corp. 1992
        !             4:                 hello Example
        !             5: 
        !             6:     FILE:       hellos.c
        !             7:     
        !             8:     USAGE:      hellos  -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 hello
        !            15:     
        !            16:     FUNCTIONS:  main() - registers server as RPC server
        !            17: 
        !            18:     COMMENTS:   This version of the distributed application that prints
        !            19:                 "hello, world" (or other string) on the server features 
        !            20:                 a client that manages its connection to the server. 
        !            21:                 It uses the binding handle hello_IfHandle, defined in 
        !            22:                 the file hello.h.
1.1.1.2   root       23: 
1.1       root       24: ****************************************************************************/
1.1.1.3 ! root       25: 
1.1       root       26: #include <stdlib.h>
                     27: #include <stdio.h>
                     28: #include <ctype.h>
1.1.1.3 ! root       29: #include "hello.h"    // header file generated by MIDL compiler 
1.1       root       30: 
1.1.1.2   root       31: #define PURPOSE \
                     32: "This Microsoft RPC Version 1.0 sample program demonstrates\n\
                     33: the use of the [string] attribute. For more information\n\
                     34: about the attributes and the RPC API functions, see the\n\
                     35: RPC programming guide and reference.\n\n"
                     36: 
1.1       root       37: void Usage(char * pszProgramName)
                     38: {
1.1.1.2   root       39:     fprintf(stderr, "%s", PURPOSE);
1.1       root       40:     fprintf(stderr, "Usage:  %s\n", pszProgramName);
                     41:     fprintf(stderr, " -p protocol_sequence\n");
                     42:     fprintf(stderr, " -e endpoint\n");
1.1.1.2   root       43:     fprintf(stderr, " -m maxcalls\n");
                     44:     fprintf(stderr, " -n mincalls\n");
                     45:     fprintf(stderr, " -f flag_wait_op\n");
1.1       root       46:     exit(1);
                     47: }
                     48: 
1.1.1.2   root       49: /* main:  register the interface, start listening for clients */
                     50: void _CRTAPI1 main(int argc, char * argv[])
1.1       root       51: {
                     52:     RPC_STATUS status;
                     53:     unsigned char * pszProtocolSequence = "ncacn_np";
1.1.1.3 ! root       54:     unsigned char * pszSecurity         = NULL;
        !            55:     unsigned char * pszEndpoint         = "\\pipe\\hello";
        !            56:     unsigned int    cMinCalls           = 1;
        !            57:     unsigned int    cMaxCalls           = 20;
        !            58:     unsigned int    fDontWait           = FALSE;
1.1       root       59:     int i;
                     60: 
1.1.1.3 ! root       61:     /* allow the user to override settings with command line switches */
1.1       root       62:     for (i = 1; i < argc; i++) {
1.1.1.3 ! root       63:         if ((*argv[i] == '-') || (*argv[i] == '/')) {
        !            64:             switch (tolower(*(argv[i]+1))) {
        !            65:             case 'p':  // protocol sequence 
        !            66:                 pszProtocolSequence = argv[++i];
        !            67:                 break;
        !            68:             case 'e':
        !            69:                 pszEndpoint = argv[++i];
        !            70:                 break;
        !            71:             case 'm':
        !            72:                 cMaxCalls = (unsigned int) atoi(argv[++i]);
        !            73:                 break;
        !            74:             case 'n':
        !            75:                 cMinCalls = (unsigned int) atoi(argv[++i]);
        !            76:                 break;
        !            77:             case 'f':
        !            78:                 fDontWait = (unsigned int) atoi(argv[++i]);
        !            79:                 break;
        !            80:             case 'h':
        !            81:             case '?':
        !            82:             default:
        !            83:                 Usage(argv[0]);
        !            84:             }
        !            85:         }
        !            86:         else
        !            87:             Usage(argv[0]);
1.1       root       88:     }
                     89: 
                     90:     status = RpcServerUseProtseqEp(pszProtocolSequence,
1.1.1.3 ! root       91:                                    cMaxCalls,   
1.1       root       92:                                    pszEndpoint,
1.1.1.3 ! root       93:                                    pszSecurity);  // Security descriptor
1.1       root       94:     printf("RpcServerUseProtseqEp returned 0x%x\n", status);
                     95:     if (status) {
1.1.1.3 ! root       96:         exit(status);
1.1       root       97:     }
                     98: 
1.1.1.3 ! root       99:     status = RpcServerRegisterIf(hello_ServerIfHandle,  // interface to register
        !           100:                                  NULL,   // MgrTypeUuid
        !           101:                                  NULL);  // MgrEpv; null means use default
1.1       root      102:     printf("RpcServerRegisterIf returned 0x%x\n", status);
                    103:     if (status) {
1.1.1.3 ! root      104:         exit(status);
1.1       root      105:     }
                    106: 
                    107:     printf("Calling RpcServerListen\n");
1.1.1.2   root      108:     status = RpcServerListen(cMinCalls,
1.1.1.3 ! root      109:                              cMaxCalls,
        !           110:                              fDontWait);
1.1       root      111:     printf("RpcServerListen returned: 0x%x\n", status);
                    112:     if (status) {
1.1.1.3 ! root      113:         exit(status);
1.1.1.2   root      114:     }
                    115: 
                    116:     if (fDontWait) {
1.1.1.3 ! root      117:         printf("Calling RpcMgmtWaitServerListen\n");
        !           118:         status = RpcMgmtWaitServerListen();  // wait operation
        !           119:         printf("RpcMgmtWaitServerListen returned: 0x%x\n", status);
        !           120:         if (status) {
        !           121:             exit(status);
        !           122:         }
1.1       root      123:     }
                    124: 
1.1.1.3 ! root      125: }  // end main()
        !           126: 
1.1       root      127: 
1.1.1.3 ! root      128: /*********************************************************************/
        !           129: /*                MIDL allocate and free                             */
        !           130: /*********************************************************************/
1.1       root      131: 
1.1.1.3 ! root      132: void __RPC_FAR * __RPC_API midl_user_allocate(size_t len)
1.1       root      133: {
                    134:     return(malloc(len));
                    135: }
                    136: 
1.1.1.3 ! root      137: void __RPC_API midl_user_free(void __RPC_FAR * ptr)
1.1       root      138: {
                    139:     free(ptr);
                    140: }
                    141: 
1.1.1.3 ! root      142: /* end file hellos.c */

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.