--- mstools/samples/rpc/mandel/server.c 2018/08/09 18:22:00 1.1.1.3 +++ mstools/samples/rpc/mandel/server.c 2018/08/09 18:24:15 1.1.1.4 @@ -1,35 +1,27 @@ -/* -//+------------------------------------------------------------------------- -// -// Microsoft RPC Version 1.0 -// Copyright (C) Microsoft Corporation, 1990 - 1992. -// -// File: mandel\server.c -// -// -// Usage: server -p protocol_sequence -// -e endpoint -// -m max calls -// -n min calls -// -s security descriptor -// -f flag for RpcServerListen -// -// Contents: Mandelbrot sample program -// -// Functions: main - register interface and listen for clients -//-------------------------------------------------------------------------- -*/ - -#include // exit -#include // HANDLE -#include // printf... -#include +/**************************************************************************** + Microsoft RPC Version 1.0 + Copyright Microsoft Corp. 1992 + mandel Example + + FILE: server.c + + USAGE: server -p protocol_sequence + -e endpoint + -m max calls + -n min calls + -f flag for RpcServerListen + + PURPOSE: Server side of RPC distributed application mandel -#include // RPC data structures and APIs -#include "mdlrpc.h" // interface -#include "mandel.h" + FUNCTIONS: main() - registers interface and listen for clients + +****************************************************************************/ + +#include +#include +#include +#include "mdlrpc.h" // header file generated by MIDL compiler -HANDLE hSharedBuf = NULL; void Usage(char * pszProgramName) { @@ -39,106 +31,99 @@ void Usage(char * pszProgramName) fprintf(stderr, " -m maxcalls\n"); fprintf(stderr, " -n mincalls\n"); fprintf(stderr, " -f flag_wait_op\n"); - fprintf(stderr, " -s security_descriptor\n"); exit(1); } -/* main: register the interface, start listening for clients */ void _CRTAPI1 main(int argc, char * argv[]) { RPC_STATUS status; unsigned char * pszProtocolSequence = "ncacn_np"; - unsigned char * pszSecurity = NULL; - unsigned char * pszEndpoint = "\\pipe\\mandel"; - unsigned int cMinCalls = 1; - unsigned int cMaxCalls = 20; - unsigned int fDontWait = FALSE; + unsigned char * pszSecurity = NULL; + unsigned char * pszEndpoint = "\\pipe\\mandel"; + 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 '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 's': - pszSecurity = 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]); } - hSharedBuf = GlobalAlloc(GMEM_FIXED, MAX_BUFSIZE); - status = RpcServerUseProtseqEp(pszProtocolSequence, - cMaxCalls, // max concurrent calls + cMaxCalls, pszEndpoint, - pszSecurity); // Security descriptor + pszSecurity); // Security descriptor printf("RpcServerUseProtseqEp returned 0x%x\n", status); if (status) { - exit(status); + exit(status); } - status = RpcServerRegisterIf( - mdlrpc_ServerIfHandle, // interface to register - NULL, // MgrTypeUuid - NULL); // MgrEpv; null means use default + status = RpcServerRegisterIf(mdlrpc_ServerIfHandle, // interface to register + NULL, // MgrTypeUuid + NULL); // MgrEpv; null means use default printf("RpcServerRegisterIf returned 0x%x\n", status); if (status) { - exit(status); + exit(status); } printf("Calling RpcServerListen\n"); - status = RpcServerListen(cMinCalls, - cMaxCalls, - fDontWait); + status = RpcServerListen(cMinCalls, + cMaxCalls, + fDontWait); printf("RpcServerListen returned: 0x%x\n", status); if (status) { - exit(status); + exit(status); } if (fDontWait) { - printf("Calling RpcMgmtWaitServerListen\n"); - status = RpcMgmtWaitServerListen(); // wait operation - printf("RpcMgmtWaitServerListen returned: 0x%x\n", status); - if (status) { - exit(status); - } + printf("Calling RpcMgmtWaitServerListen\n"); + status = RpcMgmtWaitServerListen(); // wait operation + printf("RpcMgmtWaitServerListen returned: 0x%x\n", status); + if (status) { + exit(status); + } } -} /* end main() */ +} // end main() + -static HANDLE hMidlUserFunc; +/*********************************************************************/ +/* MIDL allocate and free */ +/*********************************************************************/ -void * MIDL_user_allocate(size_t len) +void __RPC_FAR * __RPC_API midl_user_allocate(size_t len) { - hMidlUserFunc = GlobalAlloc(GMEM_FIXED, len); - return(PDWORD) (GlobalLock(hMidlUserFunc)); + return(malloc(len)); } -void MIDL_user_free(void * ptr) +void __RPC_API midl_user_free(void __RPC_FAR * ptr) { - GlobalUnlock(hMidlUserFunc); - GlobalFree(hMidlUserFunc); + free(ptr); } /* end server.c */