123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- namespace UniversalNetFrame451.IO;
- public class MessageQueue : BaseFilter, IDisposable
- {
- private EventQueue<Data> _receiveQueue;
- private EventQueue<Data> _sendQueue;
- public bool Initialize()
- {
- if (this._receiveQueue is not null)
- return false;
- if (this._sendQueue is not null)
- return false;
- this._receiveQueue = new(ReceivedQueueHandler);
- this._sendQueue = new(SendQueueHandler);
- return true;
- }
- void IDisposable.Dispose()
- {
- this._receiveQueue?.Dispose();
- this._sendQueue?.Dispose();
- this._receiveQueue = null;
- this._sendQueue = null;
- }
- public override bool Send(Data data)
- {
- if (_sendQueue is null)
- return false;
- this._sendQueue?.Enqueue(data);
- return true;
- }
- public override bool Receive(Data data)
- {
- if (this._receiveQueue is null)
- return false;
- this._receiveQueue?.Enqueue(data);
- return true;
- }
- private void SendQueueHandler(Data data)
- {
- base.Send(data);
- }
- private void ReceivedQueueHandler(Data data)
- {
- base.Receive(data);
- }
- }
- public class MessageReceiveQueue : BaseFilter, IDisposable
- {
- private EventQueue<Data> _receiveQueue;
- public bool Initialize()
- {
- if (this._receiveQueue is not null)
- return false;
- this._receiveQueue = new(ReceivedQueueHandler);
- return true;
- }
- void IDisposable.Dispose()
- {
- this._receiveQueue?.Dispose();
- this._receiveQueue = null;
- }
- public override bool Receive(Data data)
- {
- if (this._receiveQueue is null)
- return false;
- this._receiveQueue?.Enqueue(data);
- return true;
- }
- private void ReceivedQueueHandler(Data data)
- {
- base.Receive(data);
- }
- }
- public class MessageSendQueue : BaseFilter, IDisposable
- {
- private EventQueue<Data> _sendQueue;
- public bool Initialize()
- {
- if (this._sendQueue is not null)
- return false;
- this._sendQueue = new(SendQueueHandler);
- return true;
- }
- void IDisposable.Dispose()
- {
- this._sendQueue.Dispose();
- this._sendQueue = null;
- }
- public override bool Send(Data data)
- {
- if (_sendQueue is null)
- return false;
- this._sendQueue?.Enqueue(data);
- return true;
- }
- private void SendQueueHandler(Data data)
- {
- base.Send(data);
- }
- }
|