--- mstools/samples/rpc/hello/hellos.c 2018/08/09 18:20:55 1.1.1.1 +++ mstools/samples/rpc/hello/hellos.c 2018/08/09 18:21:58 1.1.1.2 @@ -1,17 +1,35 @@ /**************************************************************************** Microsoft RPC Version 1.0 Copyright Microsoft Corp. 1992 - Hello Example + hello Example FILE: hellos.c - USAGE: hellos + USAGE: hellos -p protocol_sequence + -e endpoint + -m max calls + -n min calls + -s security descriptor + -f flag for RpcServerListen + PURPOSE: Server side of RPC distributed application hello - FUNCTIONS: main() - registers server as RPC server - COMMENTS: - This distributed application prints "hello, world" on the server. - This version features a client that manages its connection to - the server. It uses the binding handle hello_IfHandle that is defined - in the generated header file hello.h. + FUNCTIONS: main() - registers server as RPC server + + COMMENTS: This sample program generates a linked list to + demonstrate how the list can be transmitted over + the network more efficiently as a sized array. + The pointers are rebuilt on the server side. + + The [transmit_as] attribute (used in the typedef of + DOUBLE_LINK_TYPE in the file hello.IDL) requires the + four user-supplied functions whose names start with + the name of the presented type, DOUBLE_LINK_TYPE. + + The [in, out] attributes applied to remote procedure + parameters require the two user-supplied functions + MIDL_user_allocate and MIDL_user_free. + + The other functions are utilities that are used to + build or display the data structures. ****************************************************************************/ #include #include @@ -21,26 +39,35 @@ #include // RPC data structures and APIs #include "hello.h" // header file generated by MIDL compiler +#define PURPOSE \ +"This Microsoft RPC Version 1.0 sample program demonstrates\n\ +the use of the [string] attribute. For more information\n\ +about the attributes 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"); + fprintf(stderr, " -s security_descriptor\n"); exit(1); } -void main(int argc, char * argv[]) +/* main: register the interface, start listening for clients */ +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 * pszSecurity = NULL; unsigned char * pszEndpoint = "\\pipe\\hello"; - unsigned char * pszOptions = NULL; - unsigned char * pszStringBinding = NULL; + unsigned int cMinCalls = 1; + unsigned int cMaxCalls = 20; + unsigned int fDontWait = FALSE; int i; // allow the user to override settings with command line switches @@ -50,17 +77,20 @@ void main(int argc, char * argv[]) 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]; + case 'm': + cMaxCalls = (unsigned int) atoi(argv[++i]); + break; + case 'n': + cMinCalls = (unsigned int) atoi(argv[++i]); break; - case 'u': - pszUuid = argv[++i]; + case 'f': + fDontWait = (unsigned int) atoi(argv[++i]); + break; + case 's': + pszSecurity = argv[++i]; break; case 'h': case '?': @@ -73,26 +103,39 @@ void main(int argc, char * argv[]) } status = RpcServerUseProtseqEp(pszProtocolSequence, - 1, // maximum concurrent calls + cMaxCalls, // max concurrent calls pszEndpoint, - 0); + pszSecurity); // Security descriptor printf("RpcServerUseProtseqEp returned 0x%x\n", status); if (status) { - exit(2); + exit(status); } - status = RpcServerRegisterIf(hello_ServerIfHandle, 0, 0); + status = RpcServerRegisterIf( + hello_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, - 12345); + status = RpcServerListen(cMinCalls, + cMaxCalls, + fDontWait); printf("RpcServerListen returned: 0x%x\n", status); if (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); + } } } /* end main() */ @@ -101,7 +144,6 @@ void main(int argc, char * argv[]) // MIDL allocate and free // ==================================================================== - void * MIDL_user_allocate(size_t len) { return(malloc(len)); @@ -113,4 +155,3 @@ void MIDL_user_free(void * ptr) } /* end hellos.c */ -