protected virtual void Write(NetContext context, Connection connection, Stream stream) { byte[] buffer = null; try { buffer = context.GetBuffer(); buffer[0] = (byte)(value >> 24); buffer[1] = (byte)(value >> 16); buffer[2] = (byte)(value >> 8); buffer[3] = (byte)(value); stream.Write(buffer, 0, 4); } finally { context.Recycle(buffer); } }
protected virtual void Write(NetContext context, Connection connection, Stream stream) { byte[] buffer = null; try { buffer = context.GetBuffer(); buffer[0] = (byte) (value >> 24); buffer[1] = (byte) (value >> 16); buffer[2] = (byte) (value >> 8); buffer[3] = (byte) (value); stream.Write(buffer, 0, 4); } finally { context.Recycle(buffer); } }
private void Grow(int newLength) { if (maxLength > 0 && newLength > maxLength) { throw new InvalidOperationException(string.Format("Buffer maximum length exceeded ({0} vs {1})", newLength, maxLength)); } int spaceRequired = checked (newLength + offset); int chunkCount = spaceRequired / NetContext.BufferSize; if ((spaceRequired % NetContext.BufferSize) != 0) { chunkCount++; } while (buffers.Count < chunkCount) { buffers.Push(context.GetBuffer()); } }
protected virtual void Write(NetContext context, Connection connection, Stream stream) { byte[] buffer = null; try { buffer = context.GetBuffer(); if(encoding.GetMaxByteCount(value.Length) <= buffer.Length || encoding.GetByteCount(value) <= buffer.Length) { int len = encoding.GetBytes(value, 0, value.Length, buffer, 0); stream.Write(buffer, 0, len); } else { // need to do things the hard way... throw new NotImplementedException(); } } finally { context.Recycle(buffer); } }
protected virtual void Write(NetContext context, Connection connection, Stream stream) { byte[] buffer = null; try { buffer = context.GetBuffer(); if (encoding.GetMaxByteCount(value.Length) <= buffer.Length || encoding.GetByteCount(value) <= buffer.Length) { int len = encoding.GetBytes(value, 0, value.Length, buffer, 0); stream.Write(buffer, 0, len); } else { // need to do things the hard way... throw new NotImplementedException(); } } finally { context.Recycle(buffer); } }
void SetFullBuffer(SocketAsyncEventArgs args) { var buffer = context.GetBuffer(); args.SetBuffer(buffer, 0, buffer.Length); }