--- mstools/samples/rpc/handles/cxhndl/cxhndls.c 2018/08/09 18:20:56 1.1 +++ mstools/samples/rpc/handles/cxhndl/cxhndls.c 2018/08/09 18:24:17 1.1.1.3 @@ -1,112 +1,137 @@ /**************************************************************************** - Microsoft RPC Version 1.0 - Copyright Microsoft Corp. 1992 - Context Handle Example - - FILE: cxhndls.c - USAGE: cxhndls -p protocol_sequence - -n network_address - -e endpoint - -o options - -u uuid + Microsoft RPC Version 1.0 + Copyright Microsoft Corp. 1992 + cxhndl Example + + FILE: cxhndls.c + + USAGE: cxhndls -p protocol_sequence + -e endpoint + -m max calls + -n min calls + -f flag for RpcServerListen - PURPOSE: Server side of RPC distributed application context + PURPOSE: Server side of RPC distributed application cxhndl + FUNCTIONS: main() - registers server as RPC server - COMMENTS: + + COMMENTS: This distributed application uses a context handle. + ****************************************************************************/ + #include -#include -#include #include #include -#include // RPC data structures and APIs -#include "cxhndl.h" // header file generated by MIDL compiler +#include "cxhndl.h" // header file generated by MIDL compiler + +#define PURPOSE \ +"This Microsoft RPC Version 1.0 sample program demonstrates\n\ +the [context_handle] attribute. For more information\n\ +about this attribute and the RPC API functions, see the\n\ +RPC programming guide and reference.\n\n" void Usage(char * pszProgramName) { + fprintf(stderr, "%s", PURPOSE); fprintf(stderr, "Usage: %s\n", pszProgramName); fprintf(stderr, " -p protocol_sequence\n"); - fprintf(stderr, " -n network_address\n"); fprintf(stderr, " -e endpoint\n"); - fprintf(stderr, " -o options\n"); - fprintf(stderr, " -u uuid\n"); + fprintf(stderr, " -m maxcalls\n"); + fprintf(stderr, " -n mincalls\n"); + fprintf(stderr, " -f flag_wait_op\n"); exit(1); } -void main(int argc, char * argv[]) +void _CRTAPI1 main(int argc, char * argv[]) { RPC_STATUS status; - unsigned char * pszUuid = "12345678-1234-1234-1234-123456789ABC"; unsigned char * pszProtocolSequence = "ncacn_np"; - unsigned char * pszNetworkAddress = NULL; - unsigned char * pszEndpoint = "\\pipe\\context"; - unsigned char * pszOptions = NULL; - unsigned char * pszStringBinding = NULL; + unsigned char * pszSecurity = NULL; + unsigned char * pszEndpoint = "\\pipe\\cxhndl"; + unsigned int cMinCalls = 1; + unsigned int cMaxCalls = 20; + unsigned int fDontWait = FALSE; int i; - // allow the user to override settings with command line switches + /* allow the user to override settings with command line switches */ for (i = 1; i < argc; i++) { - if ((*argv[i] == '-') || (*argv[i] == '/')) { - switch (tolower(*(argv[i]+1))) { - case 'p': // protocol sequence - pszProtocolSequence = argv[++i]; - break; - case 'n': // network address - pszNetworkAddress = argv[++i]; - break; - case 'e': - pszEndpoint = argv[++i]; - break; - case 'o': - pszOptions = argv[++i]; - break; - case 'u': - pszUuid = argv[++i]; - break; - case 'h': - case '?': - default: - Usage(argv[0]); - } - } - else - Usage(argv[0]); + if ((*argv[i] == '-') || (*argv[i] == '/')) { + switch (tolower(*(argv[i]+1))) { + case 'p': // protocol sequence + pszProtocolSequence = argv[++i]; + break; + case 'e': + pszEndpoint = argv[++i]; + break; + case 'm': + cMaxCalls = (unsigned int) atoi(argv[++i]); + break; + case 'n': + cMinCalls = (unsigned int) atoi(argv[++i]); + break; + case 'f': + fDontWait = (unsigned int) atoi(argv[++i]); + break; + case 'h': + case '?': + default: + Usage(argv[0]); + } + } + else + Usage(argv[0]); } status = RpcServerUseProtseqEp(pszProtocolSequence, - 1, // maximum concurrent calls + cMaxCalls, pszEndpoint, - 0); + pszSecurity); // Security descriptor printf("RpcServerUseProtseqEp returned 0x%x\n", status); if (status) { - exit(2); + exit(status); } - status = RpcServerRegisterIf(cxhndl_ServerIfHandle, 0, 0); + status = RpcServerRegisterIf(cxhndl_ServerIfHandle, // interface to register + NULL, // MgrTypeUuid + NULL); // MgrEpv; null means use default printf("RpcServerRegisterIf returned 0x%x\n", status); if (status) { - exit(2); + exit(status); } printf("Calling RpcServerListen\n"); - status = RpcServerListen(1, - 20); + status = RpcServerListen(cMinCalls, + cMaxCalls, + fDontWait); printf("RpcServerListen returned: 0x%x\n", status); if (status) { - exit(2); + exit(status); } -} /* end main() */ + if (fDontWait) { + printf("Calling RpcMgmtWaitServerListen\n"); + status = RpcMgmtWaitServerListen(); // wait operation + printf("RpcMgmtWaitServerListen returned: 0x%x\n", status); + if (status) { + exit(status); + } + } -void * MIDL_user_allocate(size_t len) +} // end main() + + +/*********************************************************************/ +/* MIDL allocate and free */ +/*********************************************************************/ + +void __RPC_FAR * __RPC_API midl_user_allocate(size_t len) { return(malloc(len)); } -void MIDL_user_free(void * ptr) +void __RPC_API midl_user_free(void __RPC_FAR * ptr) { free(ptr); } -/* end cxhndls.c */ - +/* end file cxhndls.c */