/// <summary> /// Waits for the next command sent by the server. /// </summary> /// <returns>The command sent by the server.</returns> public virtual async Task<ServerCommandData> ReceiveAsync() { AssertNotDisposed(); while (true) { if (_buffer.TryPop(out var command)) return command; try { var task = _stream?.ReadAsync(_readBuffer, 0, _readBuffer.Length, _source.Token); if (task == null) throw new StreamCommunicationClientClosedException(); var len = await task; if (_stream == null) throw new StreamCommunicationClientClosedException(); if (_readBuffer.Length == len) { CoreLog.Log(CoreLogLevel.Error, "Network buffer overflow detected!"); } _buffer.Push(_readBuffer, 0, len); } catch (TaskCanceledException) { throw new StreamCommunicationClientClosedException(); } } }
/// <summary> /// Waits for the next command sent by the server. /// </summary> /// <returns>The command sent by the server.</returns> public virtual async Task <ServerCommandData> ReceiveAsync() { AssertNotDisposed(); while (true) { if (_buffer.TryPop(out var command)) { return(command); } try { var task = _stream?.ReadAsync(_readBuffer, 0, _readBuffer.Length, _source.Token); if (task == null) { throw new StreamCommunicationClientClosedException(); } var len = await task; if (_stream == null) { throw new StreamCommunicationClientClosedException(); } if (_readBuffer.Length == len) { CoreLog.Log(CoreLogLevel.Error, "Network buffer overflow detected!"); // TODO: Could try and detect first valid command, but that could mean some vital commands were lost. } _buffer.Push(_readBuffer, 0, len); } catch (TaskCanceledException) { throw new StreamCommunicationClientClosedException(); } } }
protected override void HandleMessage(byte[] msg) { m_msgBuf.Push(msg); }