/// <summary> /// /// </summary> /// <param name="inSharedMemType"></param> /// <param name="inName"></param> /// <param name="inCapacity"></param> /// <returns></returns> internal bool InitClient(SharedMemoryType inSharedMemType, string inName, long inServerCapacity, long inClientCapacity) { bool result = true; //::::::::::::::::::::::::::::::::::::: try { _serverCapacity = inServerCapacity; _clientCapacity = inClientCapacity; _sharedMemoryManagerType = SharedMemoryManagerType.Client; result = _sharedMemoryManager.Init(_sharedMemoryManagerType, inSharedMemType, inName, TotalCapacity); if (result) { pSetBeginMemory(TotalCapacity); } } catch { result = false; } //::::::::::::::::::::::::::::::::::::: return(result); }
/// <summary> /// /// </summary> /// <param name="inSharedMemType"></param> /// <param name="inName"></param> /// <param name="inCapacity"></param> /// <returns></returns> public SharedMemoryController BuildClientController(SharedMemoryType inSharedMemType, string inName, long inServerCapacity, long inClientCapacity) { SharedMemoryController result = new SharedMemoryController(); //::::::::::::::::::::::::::::::::::::::::: result.InitClient(inSharedMemType, inName, inServerCapacity, inClientCapacity); //::::::::::::::::::::::::::::::::::::::::: return(result); }
/// <summary> /// /// </summary> /// <param name="inShareType"></param> /// <param name="inName"></param> /// <param name="inCapacity"></param> /// <returns></returns> bool pInitClient(SharedMemoryType inShareType, string inName, long inCapacity) { bool result = true; //::::::::::::::::::::::::::::: result = (inShareType == SharedMemoryType.File) ? pInitClientSharedMemMappedFile(inName) : pInitClientSharedMem(inName); //::::::::::::::::::::::::::::: return(result); }
/// <summary> /// /// </summary> /// <param name="inType"></param> /// <returns></returns> public bool Init(SharedMemoryManagerType inType, SharedMemoryType inShareType, string inName, long inCapacity) { bool result = true; //::::::::::::::::::::::::::::: result = (inType == SharedMemoryManagerType.Server) ? pInitServer(inShareType, inName, inCapacity) : pInitClient(inShareType, inName, inCapacity); //::::::::::::::::::::::::::::: return(result); }
/// <summary> /// Constructor /// </summary> /// <param name="name"> /// The name the shared memory will be given, this is combination of node, /// username, admin status, and some other ones, /// see LocalNodeProviderGlobalNames.NodeInputMemoryName for greater detail. /// </param> /// <param name="type"> /// This type determines which lock and stream needs to be instantiated /// within the shared memory class. For example, /// read only means, only create a memory stream, /// a read lock and a backing byte array and a binary reader. A write /// only type means, create a memory stream, write lock and a binary writer. /// This type however does not set the type of the memory mapped section, /// the memory mapped section itself is created /// with READWRITE access. ///</param> /// <param name="allowExistingMapping"> /// The shared memory is given a parameter to determine whether or not to /// reuse an existing mapped memory secion. When the node is first created /// this is false, however when the shared memory threads are created this /// is true. We do this because we create the shared memory when the node /// is created, at this point the there should be no shared memory with the /// same name. However when we create the reader and writer threads /// (which happens on node reuse) we want to reuse the memory. ///</param> internal SharedMemory(string name, SharedMemoryType type, bool allowExistingMapping) { this.type = type; InitializeMemoryMapping(name, allowExistingMapping); writeBytesRemaining = 0; readBytesRemaining = 0; readBytesTotal = 0; largeObjectsQueue = null; // Has the shared memory been properly created and is ready to use if (IsUsable) { // Setup the structures for either a read only or write only stream InitializeStreams(type); try { // This could fail if two different administrator accounts try and // access each others nodes as events and semaphores are protected // against cross account access InitializeSynchronization(); } catch (System.UnauthorizedAccessException) { if (writeStream != null) { // Closes binary writer and the underlying stream binaryWriter.Close(); } if (readStream != null) { // Closes binary reader and the underlying stream binaryReader.Close(); } NativeMethods.UnmapViewOfFile(pageFileView); pageFileMapping.Dispose(); } } }
/// <summary> /// Initialize the MemoryStreams which will be used to contain the serialized data from the LocalCallDescriptors. /// </summary> private void InitializeStreams(SharedMemoryType streamType) { // Initialize the .net binary formatter in case we need to use .net serialization. this.binaryFormatter = new BinaryFormatter(); this.loggingTypeCache = new Hashtable(); if (streamType == SharedMemoryType.ReadOnly) { this.readBuffer = new byte[size]; this.readStream = new MemoryStream(this.readBuffer); this.binaryReader = new BinaryReader(this.readStream); readLock = new object(); } else if (streamType == SharedMemoryType.WriteOnly) { this.writeStream = new MemoryStream(); writeLock = new object(); this.binaryWriter = new BinaryWriter(this.writeStream); } else { ErrorUtilities.VerifyThrow(false, "Unknown shared memory type."); } }