Annotation of mstools/samples/rpc/mandel/server.c, revision 1.1.1.3

1.1.1.2   root        1: /*
                      2: //+-------------------------------------------------------------------------
                      3: //
                      4: //  Microsoft RPC Version 1.0
                      5: //  Copyright (C) Microsoft Corporation, 1990 - 1992.
                      6: //
                      7: //  File:      mandel\server.c
                      8: //
1.1.1.3 ! root        9: //
        !            10: //  Usage:     server   -p protocol_sequence
        !            11: //                      -e endpoint
        !            12: //                      -m max calls
        !            13: //                      -n min calls
        !            14: //                      -s security descriptor
        !            15: //                      -f flag for RpcServerListen
        !            16: //
1.1.1.2   root       17: //  Contents:  Mandelbrot sample program
                     18: //
                     19: //  Functions: main - register interface and listen for clients
                     20: //--------------------------------------------------------------------------
                     21: */
                     22: 
1.1       root       23: #include <stdlib.h>    // exit
1.1.1.2   root       24: #include <windows.h>   // HANDLE
1.1       root       25: #include <stdio.h>     // printf...
                     26: #include <ctype.h>
                     27: 
1.1.1.2   root       28: #include <rpc.h>       // RPC data structures and APIs
1.1       root       29: #include "mdlrpc.h"    // interface
                     30: #include "mandel.h"
                     31: 
                     32: HANDLE hSharedBuf = NULL;
                     33: 
1.1.1.3 ! root       34: void Usage(char * pszProgramName)
        !            35: {
        !            36:     fprintf(stderr, "Usage:  %s\n", pszProgramName);
        !            37:     fprintf(stderr, " -p protocol_sequence\n");
        !            38:     fprintf(stderr, " -e endpoint\n");
        !            39:     fprintf(stderr, " -m maxcalls\n");
        !            40:     fprintf(stderr, " -n mincalls\n");
        !            41:     fprintf(stderr, " -f flag_wait_op\n");
        !            42:     fprintf(stderr, " -s security_descriptor\n");
        !            43:     exit(1);
        !            44: }
        !            45: 
        !            46: /* main:  register the interface, start listening for clients */
        !            47: void _CRTAPI1 main(int argc, char * argv[])
1.1       root       48: {
                     49:     RPC_STATUS status;
1.1.1.3 ! root       50:     unsigned char * pszProtocolSequence = "ncacn_np";
        !            51:     unsigned char * pszSecurity        = NULL;
        !            52:     unsigned char * pszEndpoint        = "\\pipe\\mandel";
        !            53:     unsigned int    cMinCalls          = 1;
        !            54:     unsigned int    cMaxCalls          = 20;
        !            55:     unsigned int    fDontWait          = FALSE;
        !            56:     int i;
        !            57: 
        !            58:     // allow the user to override settings with command line switches
        !            59:     for (i = 1; i < argc; i++) {
        !            60:        if ((*argv[i] == '-') || (*argv[i] == '/')) {
        !            61:            switch (tolower(*(argv[i]+1))) {
        !            62:                case 'p':  // protocol sequence
        !            63:                    pszProtocolSequence = argv[++i];
        !            64:                    break;
        !            65:                case 'e':
        !            66:                    pszEndpoint = argv[++i];
        !            67:                    break;
        !            68:                case 'm':
        !            69:                    cMaxCalls = (unsigned int) atoi(argv[++i]);
        !            70:                    break;
        !            71:                case 'n':
        !            72:                    cMinCalls = (unsigned int) atoi(argv[++i]);
        !            73:                    break;
        !            74:                case 'f':
        !            75:                    fDontWait = (unsigned int) atoi(argv[++i]);
        !            76:                    break;
        !            77:                case 's':
        !            78:                    pszSecurity = argv[++i];
        !            79:                    break;
        !            80:                case 'h':
        !            81:                case '?':
        !            82:                default:
        !            83:                    Usage(argv[0]);
        !            84:            }
        !            85:        }
        !            86:        else
        !            87:            Usage(argv[0]);
        !            88:     }
1.1       root       89: 
1.1.1.2   root       90:     hSharedBuf = GlobalAlloc(GMEM_FIXED, MAX_BUFSIZE);
1.1       root       91: 
1.1.1.3 ! root       92:     status = RpcServerUseProtseqEp(pszProtocolSequence,
        !            93:                                   cMaxCalls, // max concurrent calls
1.1.1.2   root       94:                                    pszEndpoint,
1.1.1.3 ! root       95:                                   pszSecurity);  // Security descriptor
1.1.1.2   root       96:     printf("RpcServerUseProtseqEp returned 0x%x\n", status);
1.1       root       97:     if (status) {
1.1.1.3 ! root       98:        exit(status);
1.1       root       99:     }
                    100: 
1.1.1.3 ! root      101:     status = RpcServerRegisterIf(
        !           102:                 mdlrpc_ServerIfHandle, // interface to register
        !           103:                 NULL,                // MgrTypeUuid
        !           104:                 NULL);               // MgrEpv; null means use default
1.1.1.2   root      105:     printf("RpcServerRegisterIf returned 0x%x\n", status);
1.1       root      106:     if (status) {
1.1.1.3 ! root      107:        exit(status);
1.1       root      108:     }
1.1.1.3 ! root      109: 
1.1.1.2   root      110:     printf("Calling RpcServerListen\n");
1.1.1.3 ! root      111:     status = RpcServerListen(cMinCalls,
        !           112:                             cMaxCalls,
        !           113:                             fDontWait);
        !           114:     printf("RpcServerListen returned: 0x%x\n", status);
        !           115:     if (status) {
        !           116:        exit(status);
        !           117:     }
1.1       root      118: 
1.1.1.3 ! root      119:     if (fDontWait) {
        !           120:        printf("Calling RpcMgmtWaitServerListen\n");
        !           121:        status = RpcMgmtWaitServerListen();  //  wait operation
        !           122:        printf("RpcMgmtWaitServerListen returned: 0x%x\n", status);
        !           123:        if (status) {
        !           124:            exit(status);
        !           125:        }
        !           126:     }
1.1       root      127: 
1.1.1.2   root      128: } /* end main() */
1.1       root      129: 
1.1.1.2   root      130: static HANDLE hMidlUserFunc;
1.1       root      131: 
1.1.1.2   root      132: void * MIDL_user_allocate(size_t len)
                    133: {
                    134:     hMidlUserFunc = GlobalAlloc(GMEM_FIXED, len);
                    135:     return(PDWORD) (GlobalLock(hMidlUserFunc));
                    136: }
                    137: 
                    138: void MIDL_user_free(void * ptr)
                    139: {
                    140:       GlobalUnlock(hMidlUserFunc);
                    141:       GlobalFree(hMidlUserFunc);
                    142: }
1.1       root      143: 
1.1.1.2   root      144: /* end server.c */

unix.superglobalmegacorp.com

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