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