public void Send(CanFrame canmsg) { MessageTransmitted?.Invoke( this, new CanMessageEventArgs { Message = canmsg }); }
/// <summary> /// Transmit a raw message to the IRC server /// </summary> /// <param name="data">The raw IRC message to transmit</param> public void Transmit(string data) { CancelIfDisposed(); try { _remoteTx.WriteLine(data); MessageTransmitted?.Invoke(data); } catch (Exception e) { Dispose(); TransmitFailed?.Invoke(e); } }
/// <summary> /// Sender to send enqued IRC messages to network stream as an asynchronous operation. /// </summary> private async void SenderAsync() { while (_tcpClient.Connected) { // Transmit a priority message before any other normal messages in queue if (!_prioritySendQ.IsEmpty && _prioritySendQ.TryDequeue(out string primessage)) { // transmit message and send if (await TransmitMessageAsync(primessage)) { // Fire transmitted event and apply a small sleep MessageTransmitted?.Invoke(this, new IrcTcpMessageEventArgs(primessage)); Thread.Sleep(1); } else { // Disconnect on transmit failure Disconnect(DisconnectReason.TransmitFailure); break; } } // If there are no priority message in queue send out any normal messages else if (!_sendQ.IsEmpty && _sendQ.TryDequeue(out string message)) { if (await TransmitMessageAsync(message)) { // Fire transmitted event and apply ratelimit MessageTransmitted?.Invoke(this, new IrcTcpMessageEventArgs(message)); Thread.Sleep(_rateLimit); } else { // Disconnect on transmit failure Disconnect(DisconnectReason.TransmitFailure); break; } } // Nothing to transmit else { // Apply a small sleep Thread.Sleep(1); } } }