|
|
1.1 root 1: /****************************************************************************
2: Microsoft RPC Version 1.0
3: Copyright Microsoft Corp. 1992
4: xmit Example
5:
6: FILE: xmits.c
1.1.1.2 ! root 7: USAGE: xmits -p protocol_sequence
1.1 root 8: -e endpoint
1.1.1.2 ! root 9: -m max calls
! 10: -n min calls
! 11: -s security descriptor
! 12: -f flag for RpcServerListen
1.1 root 13:
14: PURPOSE: Server side of RPC distributed application xmit
15: FUNCTIONS: main() - registers server as RPC server
16:
17: COMMENTS: This sample program generates a linked list to
18: demonstrate how the list can be transmitted over
19: the network more efficiently as a sized array.
20: The pointers are rebuilt on the server side.
21:
22: The [transmit_as] attribute (used in the typedef of
1.1.1.2 ! root 23: DOUBLE_LINK_TYPE in the file XMIT.IDL) requires the
1.1 root 24: four user-supplied functions whose names start with
1.1.1.2 ! root 25: the name of the presented type, DOUBLE_LINK_TYPE.
1.1 root 26:
27: The [in, out] attributes applied to remote procedure
28: parameters require the two user-supplied functions
29: MIDL_user_allocate and MIDL_user_free.
30:
31: The other functions are utilities that are used to
32: build or display the data structures.
33: ****************************************************************************/
34: #include <stdlib.h>
35: #include <windows.h>
36: #include <string.h>
37: #include <stdio.h>
38: #include <ctype.h>
39: #include <rpc.h> // RPC data structures and APIs
40: #include "xmit.h" // header file generated by MIDL compiler
41:
1.1.1.2 ! root 42: #include "xmitu.h" // Function prototypes for utility functions
1.1 root 43: #define PURPOSE \
44: "This Microsoft RPC Version 1.0 sample program demonstrates\n\
45: the use of the [transmit_as] attribute. For more information\n\
46: about the attributes and the RPC API functions, see the\n\
47: RPC programming guide and reference.\n\n"
48:
49: void Usage(char * pszProgramName)
50: {
51: fprintf(stderr, "%s", PURPOSE);
52: fprintf(stderr, "Usage: %s\n", pszProgramName);
53: fprintf(stderr, " -p protocol_sequence\n");
54: fprintf(stderr, " -e endpoint\n");
1.1.1.2 ! root 55: fprintf(stderr, " -m maxcalls\n");
! 56: fprintf(stderr, " -n mincalls\n");
! 57: fprintf(stderr, " -f flag_wait_op\n");
! 58: fprintf(stderr, " -s security_descriptor\n");
1.1 root 59: exit(1);
60: }
61:
62: /* main: register the interface, start listening for clients */
1.1.1.2 ! root 63: void _CRTAPI1 main(int argc, char * argv[])
1.1 root 64: {
65: RPC_STATUS status;
66: unsigned char * pszProtocolSequence = "ncacn_np";
1.1.1.2 ! root 67: unsigned char * pszSecurity = NULL;
1.1 root 68: unsigned char * pszEndpoint = "\\pipe\\xmit";
1.1.1.2 ! root 69: unsigned int cMinCalls = 1;
! 70: unsigned int cMaxCalls = 20;
! 71: unsigned int fDontWait = FALSE;
1.1 root 72: int i;
73:
74: // allow the user to override settings with command line switches
75: for (i = 1; i < argc; i++) {
76: if ((*argv[i] == '-') || (*argv[i] == '/')) {
77: switch (tolower(*(argv[i]+1))) {
78: case 'p': // protocol sequence
79: pszProtocolSequence = argv[++i];
80: break;
81: case 'e':
82: pszEndpoint = argv[++i];
83: break;
1.1.1.2 ! root 84: case 'm':
! 85: cMaxCalls = (unsigned int) atoi(argv[++i]);
1.1 root 86: break;
1.1.1.2 ! root 87: case 'n':
! 88: cMinCalls = (unsigned int) atoi(argv[++i]);
! 89: break;
! 90: case 'f':
! 91: fDontWait = (unsigned int) atoi(argv[++i]);
! 92: break;
! 93: case 's':
! 94: pszSecurity = argv[++i];
1.1 root 95: break;
96: case 'h':
97: case '?':
98: default:
99: Usage(argv[0]);
100: }
101: }
102: else
103: Usage(argv[0]);
104: }
105:
106: status = RpcServerUseProtseqEp(pszProtocolSequence,
1.1.1.2 ! root 107: cMaxCalls, // max concurrent calls
1.1 root 108: pszEndpoint,
1.1.1.2 ! root 109: pszSecurity); // Security descriptor
1.1 root 110: printf("RpcServerUseProtseqEp returned 0x%x\n", status);
111: if (status) {
1.1.1.2 ! root 112: exit(status);
1.1 root 113: }
114:
1.1.1.2 ! root 115: status = RpcServerRegisterIf(
! 116: xmit_ServerIfHandle, // interface to register
! 117: NULL, // MgrTypeUuid
! 118: NULL); // MgrEpv; null means use default
1.1 root 119: printf("RpcServerRegisterIf returned 0x%x\n", status);
120: if (status) {
1.1.1.2 ! root 121: exit(status);
1.1 root 122: }
123:
124: printf("Calling RpcServerListen\n");
1.1.1.2 ! root 125: status = RpcServerListen(cMinCalls,
! 126: cMaxCalls,
! 127: fDontWait);
1.1 root 128: printf("RpcServerListen returned: 0x%x\n", status);
129: if (status) {
1.1.1.2 ! root 130: exit(status);
! 131: }
! 132:
! 133: if (fDontWait) {
! 134: printf("Calling RpcMgmtWaitServerListen\n");
! 135: status = RpcMgmtWaitServerListen(); // wait operation
! 136: printf("RpcMgmtWaitServerListen returned: 0x%x\n", status);
! 137: if (status) {
! 138: exit(status);
! 139: }
1.1 root 140: }
141:
142: } /* end main() */
143:
1.1.1.2 ! root 144: // ====================================================================
! 145: // MIDL allocate and free
! 146: // ====================================================================
! 147:
! 148: void * MIDL_user_allocate(size_t len)
! 149: {
! 150: return(malloc(len));
! 151: }
! 152:
! 153: void MIDL_user_free(void * ptr)
! 154: {
! 155: free(ptr);
! 156: }
! 157:
1.1 root 158: /* end xmits.c */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.