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(); 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); } }
internal static string GetIdent(Connection connection) { var builder = new StringBuilder(GetAuditTimestamp()).Append(' '); if(connection == null) builder.Append("??conn??"); else { int id = connection.connectionId; builder.Append(((byte) (id >> 24)).ToString("x2")) .Append(((byte) (id >> 16)).ToString("x2")) .Append(((byte) (id >> 8)).ToString("x2")) .Append(((byte) (id)).ToString("x2")); } return builder.ToString(); }
protected virtual void Write(NetContext context, Connection connection, Stream stream) { stream.Write(value, 0, value.Length); }
protected override int ProcessIncoming(NetContext context, Connection connection, System.IO.Stream incomingBuffer) { throw new NotSupportedException(); // not expecting more incoming }
protected override void Send(NetContext context, Connection connection, object message) { EnqueueFrame(context, new StringFrame((string)message)); }
void IProtocolProcessor.InitializeClientHandshake(NetContext context, Connection connection) { InitializeClientHandshake(context, connection); }
void IProtocolProcessor.Send(NetContext context, Connection connection, object message) { Send(context, connection, message); }
protected abstract void Send(NetContext context, Connection connection, object message);
protected abstract int ProcessIncoming(NetContext context, Connection connection, System.IO.Stream incomingBuffer);
protected virtual void InitializeOutbound(NetContext context, Connection connection) { }
protected virtual void GracefulShutdown(NetContext context, Connection connection) { EnqueueFrame(context, ShutdownFrame.Default); connection.PromptToSend(context); }
void IProtocolProcessor.InitializeOutbound(NetContext context, Connection connection) { InitializeOutbound(context, connection); }
void IProtocolProcessor.GracefulShutdown(NetContext context, Connection connection) { GracefulShutdown(context, connection); }
protected virtual void InitializeClientHandshake(NetContext context, Connection connection) { /* nothing to do */ }
void IFrame.Write(NetContext context, Connection connection, Stream stream) { Write(context, connection, stream); }
int IProtocolProcessor.ProcessIncoming(NetContext context, Connection connection, System.IO.Stream incomingBuffer) { return ProcessIncoming(context, connection, incomingBuffer); }