--- mstools/samples/rpc/data/xmit/xmits.c 2018/08/09 18:20:59 1.1.1.1 +++ mstools/samples/rpc/data/xmit/xmits.c 2018/08/09 18:24:26 1.1.1.3 @@ -1,53 +1,44 @@ /**************************************************************************** - Microsoft RPC Version 1.0 - Copyright Microsoft Corp. 1992 - xmit Example - - FILE: xmits.c - USAGE: xmits -n network_address - -p protocol_sequence - -e endpoint - -o options - -u uuid - - PURPOSE: Server side of RPC distributed application xmit - FUNCTIONS: main() - registers server as RPC server - - PDOUBLE_LINK_TYPE_to_xmit - convert list to array - PDOUBLE_LINK_TYPE_from_xmit - convert array to list - PDOUBLE_LINK_TYPE_free_inst - free linked list memory - PDOUBLE_LINK_TYPE_free_xmit - free array memory - MIDL_user_allocate - user-supplied memory allocator - MIDL_user_free - user-supplied routine to free memory - - ArrayWalkProc - utility to display the array - ListWalkProc - utility to display the linked list - InsertNewNode - utility to add a node to the list - - 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 - PDOUBLE_LINK_TYPE in the file XMIT.IDL) requires the - four user-supplied functions whose names start with - the name of the presented type, PDOUBLE_LINK_TYPE. - - The [in, out] attributes applied to remote procedure - parameters require the two user-supplied functions - MIDL_user_allocate and MIDL_user_free. + Microsoft RPC Version 1.0 + Copyright Microsoft Corp. 1992 + xmit Example + + FILE: xmits.c + + USAGE: xmits -p protocol_sequence + -e endpoint + -m max calls + -n min calls + -f flag for RpcServerListen + + PURPOSE: Server side of RPC distributed application xmit + + 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 XMIT.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. - The other functions are utilities that are used to - build or display the data structures. ****************************************************************************/ + #include -#include -#include #include #include -#include // RPC data structures and APIs -#include "xmit.h" // header file generated by MIDL compiler +#include "xmit.h" // header file generated by MIDL compiler +#include "xmitu.h" // Function prototypes for utility functions #define PURPOSE \ "This Microsoft RPC Version 1.0 sample program demonstrates\n\ @@ -55,197 +46,94 @@ the use of the [transmit_as] attribute. 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"); exit(1); } -/* adds a new node to the linked list */ -/* assign the new node the value sValue and place after pPrevious */ -DOUBLE_LINK_TYPE * InsertNewNode(short sValue, DOUBLE_LINK_TYPE * pPrevious) -{ -DOUBLE_LINK_TYPE * pNew; - - pNew = (DOUBLE_LINK_TYPE *) malloc(sizeof(DOUBLE_LINK_TYPE)); - if (pNew != NULL) { - pNew->sNumber = sValue; /* insert b between a and c */ - pNew->pPrevious = pPrevious; /* prev(b) = a */ - if (pPrevious != NULL) { - pNew->pNext = pPrevious->pNext; /* next(b) = c */ - pPrevious->pNext = pNew; /* next(a) = b */ - if (pNew->pNext != NULL) - (pNew->pNext)->pPrevious = pNew; /* prev(c) = b */ - } - else - pNew->pNext = NULL; - } - return(pNew); -} - -/* display the contents of the array */ -void ArrayWalkProc(PDOUBLE_XMIT_TYPE pArray) -{ - int i; - printf("Display contents of transmitted array:\n"); - - for (i = 0; i < pArray->sSize; i++) - printf("pArray->asNumber[%d] = %d\n", i, pArray->asNumber[i]); -} - -/* display the contents of the linked list */ -void ListWalkProc(DOUBLE_LINK_TYPE * pList) -{ - printf("Display contents of doubly linked list:\n"); - while (pList != NULL) { - printf("pList @0x%x = %d, Next = 0x%x\n", pList, pList->sNumber, pList->pNext); - pList = pList->pNext; - } -} - -void * MIDL_user_allocate(size_t len) -{ - return(malloc(len)); -} - -void MIDL_user_free(void * ptr) -{ - free(ptr); -} - -/* free the doubly linked list */ -void DOUBLE_LINK_TYPE_free_inst (DOUBLE_LINK_TYPE * pList) -{ - while (pList->pNext != NULL) /* go to end of list */ - pList = pList->pNext; - for (pList = pList->pPrevious; pList != NULL; pList = pList->pPrevious) - free(pList->pNext); -} - -/* free the array structure */ -void DOUBLE_LINK_TYPE_free_xmit (DOUBLE_XMIT_TYPE * pSizedArray) -{ - free(pSizedArray); -} - - -/* convert from linked list to array */ -void DOUBLE_LINK_TYPE_to_xmit (DOUBLE_LINK_TYPE * pList, - DOUBLE_XMIT_TYPE ** ppArray) -{ - short cCount = 0; - DOUBLE_LINK_TYPE * pHead = pList; /* save pointer to start */ - DOUBLE_XMIT_TYPE * pArray; - - /* count the number of elements to allocate memory */ - for (; pList != NULL; pList = pList->pNext) - cCount++; - - /* allocate the memory for the array */ - pArray = (DOUBLE_XMIT_TYPE *) malloc(sizeof(DOUBLE_XMIT_TYPE) + (cCount * sizeof(short))); - pArray->sSize = cCount; - - /* copy the linked list contents into the array */ - cCount = 0; - for (pList = pHead; pList != NULL; pList = pList->pNext) - pArray->asNumber[cCount++] = pList->sNumber; - - /* return the address of the pointer to the array */ - *ppArray = pArray; -} - -/* convert from array to linked list */ -void DOUBLE_LINK_TYPE_from_xmit (DOUBLE_XMIT_TYPE * pArray, - DOUBLE_LINK_TYPE * pDblLinkedList) -{ - PDOUBLE_LINK_TYPE pCurrent, pNew; - - int i; - - pCurrent = pDblLinkedList; - pCurrent->sNumber = pArray->asNumber[0]; - - DOUBLE_LINK_TYPE_free_inst(pCurrent); - pCurrent->pNext = NULL; /* wipe out pointer to old list */ - - for (i = 1; i < pArray->sSize; i++) { - pNew = InsertNewNode(pArray->asNumber[i], pCurrent); - pCurrent = pNew; - } - return; -} - /* main: register the interface, start listening for clients */ -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\\xmit"; - unsigned char * pszOptions = NULL; - unsigned char * pszStringBinding = NULL; + unsigned char * pszSecurity = NULL; + unsigned char * pszEndpoint = "\\pipe\\xmit"; + 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(xmit_ServerIfHandle, 0, 0); + status = RpcServerRegisterIf(xmit_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); + } + + if (fDontWait) { + printf("Calling RpcMgmtWaitServerListen\n"); + status = RpcMgmtWaitServerListen(); // wait operation + printf("RpcMgmtWaitServerListen returned: 0x%x\n", status); + if (status) { + exit(status); + } } -} /* end main() */ +} // end main() -/* end xmits.c */ +/* end file xmits.c */