public Gram Enqueue(byte[] buffer, int offset, int length) { if (buffer == null) { throw new ArgumentNullException("buffer"); } if (!(offset >= 0 && offset < buffer.Length)) { throw new ArgumentOutOfRangeException("offset", "Offset must be greater than or equal to zero and less than the size of the buffer."); } if (length < 0 || length > buffer.Length) { throw new ArgumentOutOfRangeException("length", "Length cannot be less than zero or greater than the size of the buffer."); } if ((buffer.Length - offset) < length) { throw new ArgumentException("Offset and length do not point to a valid segment within the buffer."); } int existingBytes = (_pending.Count * _coalesceBufferSize) + (_buffered == null ? 0 : _buffered.Length); if ((existingBytes + length) > PendingCap) { throw new CapacityExceededException(); } Gram gram = null; while (length > 0) { if (_buffered == null) { // nothing yet buffered _buffered = Gram.Acquire(); } int bytesWritten = _buffered.Write(buffer, offset, length); offset += bytesWritten; length -= bytesWritten; // If it is Server it'll check the IsFull, if it is not then we'll expect that they are a ClientNetState Send if (_buffered.IsFull) { if (_pending.Count == 0) { gram = _buffered; } _pending.Enqueue(_buffered); _buffered = null; } } return(gram); }
public Gram Enqueue(byte[] buffer, int offset, int length) { if (buffer == null) { throw new ArgumentNullException("buffer"); } if (!(offset >= 0 && offset < buffer.Length)) { throw new ArgumentOutOfRangeException("offset", offset, "Offset must be greater than or equal to zero and less than the size of the buffer."); } if (length < 0 || length > buffer.Length) { throw new ArgumentOutOfRangeException("length", length, "Length cannot be less than zero or greater than the size of the buffer."); } if (buffer.Length - offset < length) { throw new ArgumentException("Offset and length do not point to a valid segment within the buffer."); } int existingBytes = _pending.Count * _CoalesceBufferSize + (_buffered?.Length ?? 0); if (existingBytes + length > PendingCap) { throw new CapacityExceededException(); } Gram gram = null; while (length > 0) { if (_buffered == null) { // nothing yet buffered _buffered = Gram.Acquire(); } int bytesWritten = _buffered.Write(buffer, offset, length); offset += bytesWritten; length -= bytesWritten; if (_buffered.IsFull) { if (_pending.Count == 0) { gram = _buffered; } _pending.Enqueue(_buffered); _buffered = null; } } return(gram); }
public Gram Enqueue(byte[] buffer, int offset, int length) { if (buffer == null) { throw new ArgumentNullException("buffer"); } if ((offset < 0) || (offset >= buffer.Length)) { throw new ArgumentOutOfRangeException("offset", offset, "Offset must be greater than or equal to zero and less than the size of the buffer."); } if ((length < 0) || (length > buffer.Length)) { throw new ArgumentOutOfRangeException("length", length, "Length cannot be less than zero or greater than the size of the buffer."); } if ((buffer.Length - offset) < length) { throw new ArgumentException("Offset and length do not point to a valid segment within the buffer."); } int num = this.getpendingCount() + ((this._buffered == null) ? 0 : this._buffered.Length); if ((num + length) > 0x177000) { throw new CapacityExceededException(); } Gram gram = null; while (length > 0) { if (this._buffered == null) { this._buffered = Gram.Acquire(); } int num2 = this._buffered.Write(buffer, offset, length); offset += num2; length -= num2; if (this._buffered.IsFull) { if (this._pending.Count == 0) { gram = this._buffered; } this._pending.Enqueue(this._buffered); this._buffered = null; } } return(gram); }