Annotation of mstools/samples/rpc/ns/nhello/nhellos.c, revision 1.1

1.1     ! root        1: /****************************************************************************
        !             2:                    Microsoft RPC Version 1.0
        !             3:                 Copyright Microsoft Corp. 1992
        !             4:                        nhello Example
        !             5: 
        !             6:     FILE:       nhellos.c
        !             7:     
        !             8:     USAGE:      nhellos  -p protocol_sequence
        !             9:                          -e endpoint
        !            10:                          -m maxcalls
        !            11:                          -n mincalls
        !            12:                          -f flag for RpcServerListen wait
        !            13:                          -a nhello_sample_nsi_entry_name
        !            14:                          -t name_syntax_type
        !            15:     
        !            16:     PURPOSE:    Server side of RPC distributed application nhello
        !            17:     
        !            18:     FUNCTIONS:  main() - registers server as RPC server
        !            19:     
        !            20:     COMMENTS:   
        !            21: 
        !            22: ****************************************************************************/
        !            23: 
        !            24: #include <stdlib.h>
        !            25: #include <stdio.h>
        !            26: #include <ctype.h>
        !            27: #include "nhello.h"   // header file generated by MIDL compiler
        !            28: 
        !            29: void Usage(char * pszProgramName)
        !            30: {
        !            31:     fprintf(stderr, "Usage:  %s\n", pszProgramName);
        !            32:     fprintf(stderr, " -p protocol_sequence\n");
        !            33:     fprintf(stderr, " -e endpoint\n");
        !            34:     fprintf(stderr, " -m maxcalls\n");
        !            35:     fprintf(stderr, " -n mincalls\n");
        !            36:     fprintf(stderr, " -f flag for RpcServerListen wait\n");
        !            37:     fprintf(stderr, " -a nhello_sample_nsi_entry_name\n");
        !            38:     fprintf(stderr, " -t name_syntax_type\n");
        !            39:     exit(1);
        !            40: }
        !            41: 
        !            42: void _CRTAPI1 main(int argc, char * argv[])
        !            43: {
        !            44:     RPC_STATUS status;
        !            45:     RPC_BINDING_VECTOR * pBindingVector;
        !            46:     unsigned char * pszEntryName    = "/.:/nhello_sample";
        !            47:     unsigned char * pszEndpoint     = "\\pipe\\nhello";
        !            48:     unsigned char * pszProtocolSequence = "ncacn_np";
        !            49:     unsigned char * pszSecurity     = NULL;
        !            50:     unsigned int    cMinCalls       = 1;
        !            51:     unsigned int    cMaxCalls       = 20;
        !            52:     unsigned int    fDontWait       = FALSE;
        !            53:     unsigned int    fNameSyntaxType = RPC_C_NS_SYNTAX_DEFAULT;
        !            54:     int i;
        !            55: 
        !            56:     /* allow the user to override settings with command line switches */
        !            57:     for (i = 1; i < argc; i++) {
        !            58:         if ((*argv[i] == '-') || (*argv[i] == '/')) {
        !            59:             switch (tolower(*(argv[i]+1))) {
        !            60:             case 'p':  // protocol sequence
        !            61:                 pszProtocolSequence = argv[++i];
        !            62:                 break;
        !            63:             case 'e':
        !            64:                 pszEndpoint = argv[++i];
        !            65:                 break;
        !            66:             case 'm':
        !            67:                 cMaxCalls = (unsigned int) atoi(argv[++i]);
        !            68:                 break;
        !            69:             case 'n':
        !            70:                 cMinCalls = (unsigned int) atoi(argv[++i]);
        !            71:                 break;
        !            72:             case 'f':
        !            73:                 fDontWait = (unsigned int) atoi(argv[++i]);
        !            74:                 break;
        !            75:             case 'a':
        !            76:                 pszEntryName = argv[++i];
        !            77:                 break;
        !            78:             case 't':
        !            79:                 fNameSyntaxType = (unsigned int) atoi(argv[++i]);
        !            80:                 break;
        !            81:             case 'h':
        !            82:             case '?':
        !            83:             default:
        !            84:                 Usage(argv[0]);
        !            85:             }
        !            86:         }    
        !            87:         else
        !            88:             Usage(argv[0]);
        !            89:     }
        !            90: 
        !            91:     status = RpcServerUseProtseqEp(pszProtocolSequence,
        !            92:                                    cMaxCalls, 
        !            93:                                    pszEndpoint,
        !            94:                                    pszSecurity);  // Security descriptor
        !            95:     printf("RpcServerUseProtseqEp returned 0x%x\n", status);
        !            96:     if (status) {
        !            97:         exit(status);
        !            98:     }
        !            99: 
        !           100:     status = RpcServerRegisterIf(nhello_ServerIfHandle, // interface to register
        !           101:                                  NULL,   // MgrTypeUuid
        !           102:                                  NULL);  // MgrEpv; null means use default
        !           103:     printf("RpcServerRegisterIf returned 0x%x\n", status);
        !           104:     if (status) {
        !           105:         exit(status);
        !           106:     }
        !           107: 
        !           108:     status = RpcServerInqBindings(&pBindingVector);
        !           109:     printf("RpcServerInqBindings returned 0x%x\n", status);
        !           110:     if (status) {
        !           111:        exit(status);
        !           112:     }
        !           113: 
        !           114:     status = RpcNsBindingExport(fNameSyntaxType,  // name syntax type
        !           115:                                 pszEntryName,     // nsi entry name 
        !           116:                                 nhello_ServerIfHandle,
        !           117:                                 pBindingVector,   // set in previous call 
        !           118:                                 NULL);            // UUID vector 
        !           119:     printf("RpcNsBindingExport returned 0x%x\n", status);
        !           120:     if (status) {
        !           121:         exit(status);
        !           122:     }
        !           123: 
        !           124:     printf("Calling RpcServerListen\n");
        !           125:     status = RpcServerListen(cMinCalls,
        !           126:                              cMaxCalls,
        !           127:                              fDontWait);  // wait flag 
        !           128:     printf("RpcServerListen returned: 0x%x\n", status);
        !           129:     if (status) {
        !           130:         exit(status);
        !           131:     }
        !           132: 
        !           133:     if (fDontWait) {
        !           134:         printf("Calling RpcMgmtWaitServerListen\n");
        !           135:         status = RpcMgmtWaitServerListen();  //  wait operation
        !           136:         printf("RpcMgmtWaitServerListen returned: 0x%x\n", status);
        !           137:         if (status) {
        !           138:             exit(status);
        !           139:         }
        !           140:     }
        !           141: 
        !           142: }  // end main() 
        !           143: 
        !           144: 
        !           145: /*********************************************************************/
        !           146: /*                 MIDL allocate and free                            */
        !           147: /*********************************************************************/
        !           148: 
        !           149: void __RPC_FAR * __RPC_API midl_user_allocate(size_t len)
        !           150: {
        !           151:     return(malloc(len));
        !           152: }
        !           153: 
        !           154: void __RPC_API midl_user_free(void __RPC_FAR * ptr)
        !           155: {
        !           156:     free(ptr);
        !           157: }
        !           158: 
        !           159: /* end file nhellos.c */

unix.superglobalmegacorp.com

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