/// <summary> /// Stops listening to the specified end point. Does not close any connections. /// </summary> /// <param name="endPoint">The end point</param> public override void StopListening(object endPoint) { BinaryLogWriter binaryLogWriter = this.ITransportContext.BinaryLogWriter; if (this._smAcceptConnectionClosure != null) { // LOG: if ( binaryLogWriter != null && binaryLogWriter[LogCategory.Connection] > 0 ) { binaryLogWriter.WriteEvent(LogCategory.AcceptingConnection, "SharedMemoryConnectionManager.StopListening", LogMessageType.ListeningStopped, null, null, null, null, GenuineUtility.CurrentThreadId, Thread.CurrentThread.Name, null, null, -1, 0, 0, 0, this._smAcceptConnectionClosure.ShareName, null, null, null, "\"{0}\" is not now listened.", this._smAcceptConnectionClosure.ShareName); } this._smAcceptConnectionClosure.StopListening.Set(); this._smAcceptConnectionClosure = null; } }
/// <summary> /// Starts listening to the specified end point and accepting incoming connections. /// </summary> /// <param name="endPoint">The end point.</param> public override void StartListening(object endPoint) { BinaryLogWriter binaryLogWriter = this.ITransportContext.BinaryLogWriter; if (this._smAcceptConnectionClosure != null) throw GenuineExceptions.Get_Server_EndPointIsAlreadyBeingListenedTo(this._smAcceptConnectionClosure.ShareName); SharedMemoryConnection sharedMemoryConnection = null; using (new ReaderAutoLocker(this._disposeLock)) { if (this._disposed) throw OperationException.WrapException(this._disposeReason); } string shareName = endPoint as string; if (shareName == null || shareName.Length <= 0 || ! shareName.StartsWith("gshmem")) throw GenuineExceptions.Get_Server_IncorrectAddressToListen(shareName); try { sharedMemoryConnection = new SharedMemoryConnection(this.ITransportContext, shareName, true, true); this._smAcceptConnectionClosure = new SMAcceptConnectionClosure(this.ITransportContext, sharedMemoryConnection, this, shareName); this.ITransportContext.IGenuineEventProvider.Fire(new GenuineEventArgs(GenuineEventType.GeneralListenerStarted, null, this.Local, endPoint)); Thread thread = new Thread(new ThreadStart(this._smAcceptConnectionClosure.AcceptConnections)); thread.IsBackground = true; thread.Start(); // LOG: if ( binaryLogWriter != null && binaryLogWriter[LogCategory.Connection] > 0 ) { binaryLogWriter.WriteEvent(LogCategory.AcceptingConnection, "SharedMemoryConnectionManager.StartListening", LogMessageType.ListeningStarted, null, null, null, null, GenuineUtility.CurrentThreadId, Thread.CurrentThread.Name, null, null, -1, 0, 0, 0, shareName, null, null, null, "\"{0}\" is now listened.", shareName); } } catch(Exception ex) { // LOG: if ( binaryLogWriter != null && binaryLogWriter[LogCategory.Connection] > 0 ) { binaryLogWriter.WriteEvent(LogCategory.AcceptingConnection, "SharedMemoryConnectionManager.StartListening", LogMessageType.ListeningStarted, ex, null, null, null, GenuineUtility.CurrentThreadId, Thread.CurrentThread.Name, null, null, -1, 0, 0, 0, shareName, null, null, null, "Listening to \"{0}\" cannot be started.", shareName); } if (sharedMemoryConnection != null) sharedMemoryConnection.ReleaseUnmanagedResources(); throw; } }