--- 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:20:56 1.1.1.2 @@ -1,69 +1,72 @@ +/* +//+------------------------------------------------------------------------- +// +// Microsoft RPC Version 1.0 +// Copyright (C) Microsoft Corporation, 1990 - 1992. +// +// File: mandel\server.c +// +// Contents: Mandelbrot sample program +// +// Functions: main - register interface and listen for clients +// +//-------------------------------------------------------------------------- +*/ + #include // exit -#include // Sleep... +#include // HANDLE #include // printf... -#include // strlen... #include -#include // RPC data structures and APIs +#include // RPC data structures and APIs #include "mdlrpc.h" // interface #include "mandel.h" - HANDLE hSharedBuf = NULL; void main(void) { - RPC_HANDLE Server, Address, Interface; RPC_STATUS status; + char * pszEndpoint = "\\pipe\\mandel"; + hSharedBuf = GlobalAlloc(GMEM_FIXED, MAX_BUFSIZE); /* 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; - status = RpcCreateServer( (RPC_EVENT_HANDLERS *)0, - &Server); + status = RpcServerUseProtseqEp("ncacn_np", + 1, // maximum concurrent calls + pszEndpoint, + 0); + printf("RpcServerUseProtseqEp returned 0x%x\n", status); if (status) { - printf("RpcCreateServer: 0x%x\n", status); exit(2); } - status = RpcAddAddress(Server, - &mdlrpc_ProtocolStack, - 0, // address flags - &Address, - (void *) 0, // reserved - RpcNormalResourceUsage, - 0L); // timeout + status = RpcServerRegisterIf(mdlrpc_ServerIfHandle, 0, 0); + printf("RpcServerRegisterIf returned 0x%x\n", status); if (status) { - printf("RpcAddAddress: 0x%x\n", status); exit(2); } + printf("Calling RpcServerListen\n"); - status = RpcAddInterface(Server, - &mdlrpc_ProtocolStack, - &Interface, - (void *) 0, // reserved - &mdlrpc_DispatchTable); - if (status) { - printf("RpcAddInterface: 0x%x\n", status); - exit(2); - } -// do it once... - hSharedBuf = LocalAlloc(LMEM_MOVEABLE, MAX_BUFSIZE); + status = RpcServerListen(1, + 200); // a very large number - printf("mdlrpc server started. Waiting for client requests...\n"); +} /* end main() */ - while (1) - Sleep(5000); +static HANDLE hMidlUserFunc; -} /* end main() */ +void * MIDL_user_allocate(size_t len) +{ + hMidlUserFunc = GlobalAlloc(GMEM_FIXED, len); + return(PDWORD) (GlobalLock(hMidlUserFunc)); +} + +void MIDL_user_free(void * ptr) +{ + GlobalUnlock(hMidlUserFunc); + GlobalFree(hMidlUserFunc); +} -/* end mdlrpc\server.c */ +/* end server.c */