|
|
1.1 root 1: /**************************************************************************** 1.1.1.3 ! root 2: Microsoft RPC Version 1.0 ! 3: Copyright Microsoft Corp. 1992 ! 4: cxhndl Example ! 5: ! 6: FILE: cxhndlp.c ! 7: ! 8: PURPOSE: Remote procedures used in server application cxhndls ! 9: ! 10: FUNCTIONS: RemoteOpen() - Open the file ! 11: RemoteRead() - Read a buffer's worth of the file ! 12: RemoteClose() - Close the file and shutdown server ! 13: Shutdown() - Shutdown the server ! 14: ! 15: COMMENTS: This distributed application uses a context handle. 1.1 root 16: 17: ****************************************************************************/ 18: 19: #include <stdlib.h> 1.1.1.3 ! root 20: #include <stdio.h> 1.1 root 21: #include <string.h> 1.1.1.3 ! root 22: #include "cxhndl.h" // header file generated by MIDL compiler 1.1 root 23: 24: 25: typedef struct { 1.1.1.3 ! root 26: FILE *hFile; 1.1 root 27: char achFile[256]; 28: } FILE_CONTEXT_TYPE; 29: 30: 1.1.1.3 ! root 31: /* This remote procedure opens a file on the server. */ ! 32: short RemoteOpen(PCONTEXT_HANDLE_TYPE *pphContext, ! 33: unsigned char *pszFileName ! 34: ) 1.1 root 35: { 1.1.1.3 ! root 36: FILE *hFile; ! 37: FILE_CONTEXT_TYPE *pFileContext; ! 38: ! 39: if ((hFile = fopen(pszFileName, "r")) == NULL) { ! 40: *pphContext = (PCONTEXT_HANDLE_TYPE) NULL; ! 41: return(-1); ! 42: } ! 43: else { ! 44: pFileContext = (FILE_CONTEXT_TYPE *) ! 45: midl_user_allocate(sizeof(FILE_CONTEXT_TYPE)); ! 46: pFileContext->hFile = hFile; ! 47: strcpy(pFileContext->achFile, pszFileName); ! 48: *pphContext = (PCONTEXT_HANDLE_TYPE) pFileContext; ! 49: return(0); ! 50: } 1.1 root 51: } 52: 1.1.1.3 ! root 53: /* This remote procedure reads a file on the server. */ ! 54: short RemoteRead(PCONTEXT_HANDLE_TYPE phContext, ! 55: unsigned char *pbBuf, ! 56: short *pcbBuf) 1.1 root 57: { 1.1.1.3 ! root 58: FILE_CONTEXT_TYPE *pFileContext; 1.1 root 59: 60: printf("in RemoteRead\n"); 61: 1.1.1.3 ! root 62: pFileContext = (FILE_CONTEXT_TYPE *) phContext; 1.1 root 63: *pcbBuf = (short) fread(pbBuf, 1.1.1.3 ! root 64: sizeof(char), ! 65: BUFSIZE, ! 66: pFileContext->hFile); 1.1 root 67: return(*pcbBuf); 68: } 69: 1.1.1.3 ! root 70: /* This remote procedure closes a file on the server. */ ! 71: short RemoteClose(PCONTEXT_HANDLE_TYPE *pphContext) ! 72: { ! 73: FILE_CONTEXT_TYPE *pFileContext; ! 74: ! 75: printf("in RemoteClose\n"); ! 76: ! 77: pFileContext = (FILE_CONTEXT_TYPE *) *pphContext; ! 78: ! 79: if ( fclose( pFileContext->hFile ) == 0) ! 80: { ! 81: *pphContext = NULL; ! 82: return(0); ! 83: } ! 84: else ! 85: /* Context Rundown routine will attempt to close it again */ ! 86: return(-1); ! 87: } ! 88: ! 89: /* The Shutdown procedure tells the server to stop listening */ ! 90: /* for client requests. */ 1.1 root 91: void Shutdown(void) 92: { 93: RPC_STATUS status; 94: 95: printf("Calling RpcMgmtStopServerListening\n"); 96: status = RpcMgmtStopServerListening(NULL); 97: printf("RpcMgmtStopServerListening returned: 0x%x\n", status); 98: if (status) { 1.1.1.3 ! root 99: exit(status); 1.1 root 100: } 101: 102: printf("Calling RpcServerUnregisterIf\n"); 103: status = RpcServerUnregisterIf(NULL, NULL, FALSE); 104: printf("RpcServerUnregisterIf returned 0x%x\n", status); 105: if (status) { 1.1.1.3 ! root 106: exit(status); 1.1 root 107: } 108: } 109: 1.1.1.3 ! root 110: /* The rundown routine is associated with the context handle type. */ ! 111: void __RPC_USER PCONTEXT_HANDLE_TYPE_rundown(PCONTEXT_HANDLE_TYPE phContext) 1.1 root 112: { 1.1.1.3 ! root 113: FILE_CONTEXT_TYPE *pFileContext; 1.1 root 114: 1.1.1.3 ! root 115: printf("Context rundown routine\n"); 1.1 root 116: 1.1.1.3 ! root 117: pFileContext = (FILE_CONTEXT_TYPE *) phContext; ! 118: if (pFileContext->hFile != NULL) ! 119: fclose(pFileContext->hFile); ! 120: } 1.1 root 121: 1.1.1.3 ! root 122: /* end file cxhndlp.c */ 1.1 root 123:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.