public override int GetHashCode() { using (DeadlockMonitor.Lock(this.ThisLock)) { return(this.Managers.Count + this.Members.Count); } }
public override string ToString() { using (DeadlockMonitor.Lock(this.ThisLock)) { return(this.Name); } }
protected override void ProtectedImport(Stream stream, BufferManager bufferManager) { using (DeadlockMonitor.Lock(this.ThisLock)) { Encoding encoding = new UTF8Encoding(false); byte[] lengthBuffer = new byte[4]; for (; ;) { if (stream.Read(lengthBuffer, 0, lengthBuffer.Length) != lengthBuffer.Length) { return; } int length = NetworkConverter.ToInt32(lengthBuffer); byte id = (byte)stream.ReadByte(); using (RangeStream rangeStream = new RangeStream(stream, stream.Position, length, true)) { if (id == (byte)SerializeId.CommandMessage) { this.CommandMessages.Add(CommandMessage.Import(rangeStream, bufferManager)); } } } } }
public override ChannelConfig DeepClone() { using (DeadlockMonitor.Lock(this.ThisLock)) { using (var bufferManager = new BufferManager()) using (var stream = this.Export(bufferManager)) { return(ChannelConfig.Import(stream, bufferManager)); } } }
public override void Start() { if (_disposed) { throw new ObjectDisposedException(this.GetType().FullName); } using (DeadlockMonitor.Lock(this.ThisLock)) { if (this.State == ManagerState.Start) { return; } _state = ManagerState.Start; } }
public ConnectionBase AcceptConnection(out byte[] id) { id = null; using (DeadlockMonitor.Lock(this.ThisLock)) { if (this.State == ManagerState.Stop) { return(null); } try { ConnectionBase connection = null; for (int i = 0; i < _listeners.Count; i++) { if (_listeners[i].Pending()) { var socket = _listeners[i].AcceptTcpClient().Client; connection = new TcpConnection(socket, ServerManager.MaxReceiveCount, _bufferManager); break; } } if (connection != null) { var secureConnection = new SecureServerConnection(connection, this.DigitalSignature, _bufferManager); secureConnection.Connect(new TimeSpan(0, 0, 20)); id = secureConnection.PublicKey; return(new CompressConnection(secureConnection, ServerManager.MaxReceiveCount, _bufferManager)); } } catch (Exception) { } return(null); } }
void connectionManager_PullMessagesEvent(object sender, MessagesEventArgs e) { var connectionManager = sender as ConnectionManager; if (connectionManager == null) { return; } using (DeadlockMonitor.Lock(this.ThisLock)) { using (DeadlockMonitor.Lock(_receiveMessageQueue.ThisLock)) { foreach (var item in e.Messages) { _receiveMessageQueue.Enqueue(new KeyValuePair <byte[], CommandMessage>(_connectionId[connectionManager], item)); } } } }
public override Stream Export(BufferManager bufferManager) { using (DeadlockMonitor.Lock(this.ThisLock)) { List <Stream> streams = new List <Stream>(); // CommandMessages foreach (var m in this.CommandMessages) { Stream exportStream = m.Export(bufferManager); BufferStream bufferStream = new BufferStream(bufferManager); bufferStream.Write(NetworkConverter.GetBytes((int)exportStream.Length), 0, 4); bufferStream.WriteByte((byte)SerializeId.CommandMessage); streams.Add(new JoinStream(bufferStream, exportStream)); } return(new JoinStream(streams)); } }
public void Close() { if (_disposed) { throw new ObjectDisposedException(this.GetType().FullName); } using (DeadlockMonitor.Lock(this.ThisLock)) { try { _connection.Close(new TimeSpan(0, 0, 30)); this.OnClose(new EventArgs()); } catch (Exception ex) { throw new ConnectionManagerException(ex.Message, ex); } } }
private void ConnectionManagerThread(object state) { Thread.CurrentThread.Name = "ConnectionManagerThread"; var connectionManager = state as ConnectionManager; if (connectionManager == null) { return; } for (; ;) { if (this.State == ManagerState.Stop) { return; } if (!_connectionManagers.Contains(connectionManager)) { return; } using (DeadlockMonitor.Lock(_sendMessageQueue.ThisLock)) { if (!_sendMessageQueue.ContainsKey(_connectionId[connectionManager])) { _sendMessageQueue[_connectionId[connectionManager]] = new WaitQueue <IEnumerable <CommandMessage> >(); } } var messages = _sendMessageQueue[_connectionId[connectionManager]].Dequeue(); connectionManager.PushMessages(messages); foreach (var item in messages) { _bufferManager.ReturnBuffer(item.Content.Array); } } }