/// <summary> /// Invokes the NewConnection event with the supplied connection. /// </summary> /// <param name="msg">The user sent bytes that were received as part of the handshake.</param> /// <param name="connection">The connection to pass in the arguments.</param> /// <remarks> /// Implementers should call this to invoke the <see cref="NewConnection"/> event before data is received so that /// subscribers do not miss any data that may have been sent immediately after connecting. /// </remarks> protected void InvokeNewConnection(MessageReader msg, Connection connection) { // Make a copy to avoid race condition between null check and invocation Action<NewConnectionEventArgs> handler = NewConnection; if (handler != null) { handler(new NewConnectionEventArgs(msg, connection)); } else { msg.Recycle(); } }
/// <summary> /// Invokes the DataReceived event. /// </summary> /// <param name="msg">The bytes received.</param> /// <param name="sendOption">The <see cref="SendOption"/> the message was received with.</param> /// <remarks> /// Invokes the <see cref="DataReceived"/> event on this connection to alert subscribers a new message has been /// received. The bytes and the send option that the message was sent with should be passed in to give to the /// subscribers. /// </remarks> protected void InvokeDataReceived(MessageReader msg, SendOption sendOption) { //Make a copy to avoid race condition between null check and invocation Action <DataReceivedEventArgs> handler = DataReceived; if (handler != null) { handler(new DataReceivedEventArgs(msg, sendOption)); } else { msg.Recycle(); } }