--- mstools/samples/rpc/mandel/server.c 2018/08/09 18:20:01 1.1.1.1 +++ mstools/samples/rpc/mandel/server.c 2018/08/09 18:24:15 1.1.1.4 @@ -1,69 +1,129 @@ -#include // exit -#include // Sleep... -#include // printf... -#include // strlen... -#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 -#include // RPC data structures and APIs -#include "mdlrpc.h" // interface -#include "mandel.h" + PURPOSE: Server side of RPC distributed application mandel + FUNCTIONS: main() - registers interface and listen for clients -HANDLE hSharedBuf = NULL; +****************************************************************************/ -void main(void) -{ - RPC_HANDLE Server, Address, Interface; - RPC_STATUS status; +#include +#include +#include +#include "mdlrpc.h" // header file generated by MIDL compiler -/* Select named pipes as the transport type and provide the */ -/* name of the named pipe that is used for RPC. */ -/* The server specifies the pipe name in the form: */ -/* \device\namedpipe\pipename */ -/* In this example, the pipename is "mdlrpc" */ - - mdlrpc_ProtocolStack.TransportType = RPC_TRANSPORT_NAMEPIPE; - mdlrpc_ProtocolStack.TransportInfo = "\\device\\namedpipe\\mdlrpc"; - mdlrpc_ProtocolStack.TransportInfoLength = \ - strlen(mdlrpc_ProtocolStack.TransportInfo) + 1; +void Usage(char * pszProgramName) +{ + fprintf(stderr, "Usage: %s\n", pszProgramName); + fprintf(stderr, " -p protocol_sequence\n"); + fprintf(stderr, " -e endpoint\n"); + fprintf(stderr, " -m maxcalls\n"); + fprintf(stderr, " -n mincalls\n"); + fprintf(stderr, " -f flag_wait_op\n"); + exit(1); +} - status = RpcCreateServer( (RPC_EVENT_HANDLERS *)0, - &Server); +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; + int i; + + /* 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 'h': + case '?': + default: + Usage(argv[0]); + } + } + else + Usage(argv[0]); + } + + status = RpcServerUseProtseqEp(pszProtocolSequence, + cMaxCalls, + pszEndpoint, + pszSecurity); // Security descriptor + printf("RpcServerUseProtseqEp returned 0x%x\n", status); if (status) { - printf("RpcCreateServer: 0x%x\n", status); - exit(2); + exit(status); } - status = RpcAddAddress(Server, - &mdlrpc_ProtocolStack, - 0, // address flags - &Address, - (void *) 0, // reserved - RpcNormalResourceUsage, - 0L); // timeout + status = RpcServerRegisterIf(mdlrpc_ServerIfHandle, // interface to register + NULL, // MgrTypeUuid + NULL); // MgrEpv; null means use default + printf("RpcServerRegisterIf returned 0x%x\n", status); if (status) { - printf("RpcAddAddress: 0x%x\n", status); - exit(2); + exit(status); } - status = RpcAddInterface(Server, - &mdlrpc_ProtocolStack, - &Interface, - (void *) 0, // reserved - &mdlrpc_DispatchTable); + printf("Calling RpcServerListen\n"); + status = RpcServerListen(cMinCalls, + cMaxCalls, + fDontWait); + printf("RpcServerListen returned: 0x%x\n", status); if (status) { - printf("RpcAddInterface: 0x%x\n", status); - exit(2); + exit(status); + } + + if (fDontWait) { + printf("Calling RpcMgmtWaitServerListen\n"); + status = RpcMgmtWaitServerListen(); // wait operation + printf("RpcMgmtWaitServerListen returned: 0x%x\n", status); + if (status) { + exit(status); + } } -// do it once... - hSharedBuf = LocalAlloc(LMEM_MOVEABLE, MAX_BUFSIZE); - printf("mdlrpc server started. Waiting for client requests...\n"); +} // end main() + - while (1) - Sleep(5000); +/*********************************************************************/ +/* MIDL allocate and free */ +/*********************************************************************/ -} /* end main() */ +void __RPC_FAR * __RPC_API midl_user_allocate(size_t len) +{ + return(malloc(len)); +} + +void __RPC_API midl_user_free(void __RPC_FAR * ptr) +{ + free(ptr); +} -/* end mdlrpc\server.c */ +/* end server.c */