|
|
1.1 ! root 1: /************************************************************************ ! 2: * ! 3: * bndbufs.c - sample program demonstrating the server initialization of ! 4: * the distributed bounded buffer solution ! 5: * ! 6: * Frederick Chong ! 7: * Microsoft Developer Support ! 8: * Copyright (c) 1992, 1993 Microsoft Corporation ! 9: * ! 10: *************************************************************************/ ! 11: ! 12: ! 13: #include <windows.h> ! 14: #include <stdio.h> ! 15: #include <string.h> ! 16: #include <stdlib.h> ! 17: #include <malloc.h> ! 18: #include <rpc.h> ! 19: #include "common.h" ! 20: #include "bndbuf.h" ! 21: ! 22: ! 23: // Synchronization primitives to shared buffer ! 24: ! 25: extern HANDLE hMutex; // Handle to mutex ! 26: extern HANDLE hEmptySem; // Handle to empty semaphore ! 27: extern HANDLE hFullSem; // Handle to full semaphore ! 28: ! 29: ! 30: // This is the shared buffer ! 31: ! 32: extern char buffer[MAX_ITEM][MAX_SIZE]; ! 33: ! 34: ! 35: DWORD retCode; ! 36: ! 37: ! 38: /************************************************************************ ! 39: ! 40: void Usage(char * pszProgramName) ! 41: ! 42: prints out the command line options for starting the server ! 43: ! 44: *************************************************************************/ ! 45: ! 46: void Usage(char * pszProgramName) ! 47: { ! 48: fprintf(stderr, "Usage: %s\n", pszProgramName); ! 49: fprintf(stderr, " -p protocol_sequence\n"); ! 50: fprintf(stderr, " -e endpoint\n"); ! 51: ExitProcess(1); ! 52: } ! 53: ! 54: ! 55: /************************************************************************* ! 56: ! 57: void _CRTAPI1 main(int argc, char *argv[]) ! 58: ! 59: Parses the command line arguments which allow the user to override the ! 60: default protocol sequence and endpoint. It then initializes the ! 61: synchronization primitives to be used for the central buffer pool. ! 62: Finally, it registers its interface with the name service and then ! 63: listens for an incoming call. ! 64: ! 65: **************************************************************************/ ! 66: ! 67: void _CRTAPI1 main(int argc, char *argv[]) ! 68: { ! 69: ! 70: RPC_STATUS status; ! 71: RPC_BINDING_VECTOR * pBindingVector; ! 72: ! 73: unsigned char * pszEndpoint = "\\pipe\\boundbuf"; ! 74: unsigned char * pszProtocolSequence = "ncacn_np"; ! 75: ! 76: int i; ! 77: ! 78: ! 79: // allow the user to override settings with command line switches ! 80: for (i = 1; i < argc; i++) ! 81: { ! 82: if ((*argv[i] == '-') || (*argv[i] == '/')) ! 83: { ! 84: switch (tolower(*(argv[i]+1))) ! 85: { ! 86: case 'p': // protocol sequence ! 87: pszProtocolSequence = argv[++i]; ! 88: break; ! 89: case 'e': ! 90: pszEndpoint = argv[++i]; ! 91: break; ! 92: case 'h': ! 93: case '?': ! 94: default: ! 95: Usage(argv[0]); ! 96: } ! 97: } ! 98: ! 99: else ! 100: Usage(argv[0]); ! 101: } ! 102: ! 103: ! 104: ! 105: ! 106: // Create semaphores and mutex for synchronization ! 107: ! 108: hMutex = CreateMutex(NULL, ! 109: FALSE, ! 110: "Buffer_Mutex"); ! 111: ! 112: if (hMutex == NULL) ! 113: { ! 114: retCode = GetLastError(); ! 115: printf("\nCreateMutex returns error %d\n", retCode); ! 116: ExitProcess(0); ! 117: } ! 118: ! 119: ! 120: if ((hEmptySem = CreateSemaphore(NULL, ! 121: MAX_ITEM, ! 122: MAX_ITEM, ! 123: "Empty_Sem")) == NULL) ! 124: ! 125: { ! 126: retCode = GetLastError(); ! 127: printf("\nCreateSemaphore for empty returns error %d\n", retCode); ! 128: ExitProcess(0); ! 129: } ! 130: ! 131: ! 132: if ((hFullSem = CreateSemaphore(NULL, ! 133: 0, ! 134: MAX_ITEM, ! 135: "Full_Sem")) == NULL) ! 136: ! 137: { ! 138: retCode = GetLastError(); ! 139: printf("\nCreateSemaphore for full returns error %d\n", retCode); ! 140: ExitProcess(0); ! 141: } ! 142: ! 143: ! 144: ! 145: // Initialize RPC Interface server ! 146: ! 147: ! 148: status = RpcServerUseProtseqEp((unsigned char *)pszProtocolSequence, ! 149: MAXCALLS, ! 150: pszEndpoint, ! 151: 0); ! 152: printf("RpcServerUseProtseqEp returned %d\n", status); ! 153: if (status) ! 154: ExitProcess(2); ! 155: ! 156: ! 157: status = RpcServerRegisterIf(bndbufh_ServerIfHandle, ! 158: 0, ! 159: 0); ! 160: printf("RpcServerRegisterIf returned %d\n", status); ! 161: if (status) ! 162: ExitProcess(2); ! 163: ! 164: ! 165: status = RpcServerInqBindings(&pBindingVector); ! 166: printf("RpcServerInqBindings returned %d\n", status); ! 167: if (status) ! 168: ExitProcess(2); ! 169: ! 170: ! 171: status = RpcNsBindingExport(RPC_C_NS_SYNTAX_DEFAULT, /* name syntax */ ! 172: "/.:/Boundbuf_sample", /* name */ ! 173: bndbufh_ServerIfHandle, ! 174: pBindingVector, ! 175: NULL); ! 176: printf("RpcNsBindingExport returned %d\n", status); ! 177: if (status) ! 178: ExitProcess(2); ! 179: ! 180: ! 181: printf("Calling RpcServerListen\n"); ! 182: status = RpcServerListen(1, ! 183: MAXCALLS, ! 184: 0); ! 185: printf("RpcServerListen returned %d\n", status); ! 186: if (status) ! 187: ExitProcess(2); ! 188: ! 189: } ! 190: ! 191: ! 192: /************************************************************************** ! 193: MIDL allocate and free ! 194: ***************************************************************************/ ! 195: ! 196: void __RPC_FAR * __RPC_API MIDL_user_allocate(size_t len) ! 197: { ! 198: return(malloc(len)); ! 199: } ! 200: ! 201: void __RPC_API MIDL_user_free(void __RPC_FAR * ptr) ! 202: { ! 203: free(ptr); ! 204: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.