/// <summary> /// 构造函数 /// </summary> /// <param name="config">网络传输配置</param> /// <param name="rev">接收函数回调</param> public TransferChannel(TransferConfig config, Action <ReceiveDataItem> rev) { if (config == null) { config = new TransferConfig(); } else { config.Validate(); } if (rev == null) { throw new ArgumentNullException(nameof(rev)); } this._config = config; for (int i = 0; i < config.TransferThreadCount; i++) { this.AddParseDispoatchThread(); } if (config.NetConfig.Protocal == TransferProtocal.Udp) { this._net = new UdpTransferNet(); } else { this._net = new TcpTransferNet(); } this._net.Init(config.NetConfig, this.NetRev); this._receiver = new TransferReceiver(this._config, this._net, rev); }
public TransferReceiver(TransferConfig config, ITransferNet net, Action <ReceiveDataItem> rev) { this._config = config; this._net = net; this._rev = rev; TransferParaManager.Init(config); this._revOutputQueue = new AsynQueue <ReceiveDataItem>(this.RevitemOutput, "拉收到数据输出线程", true, true); int threadCount = config.TransferThreadCount; this._reqDataThreads = new ThreadEx[threadCount]; this._reqDataThreadsEventHandles = new AutoResetEvent[threadCount]; for (int i = 0; i < threadCount; i++) { this._reqDataThreadsEventHandles[i] = new AutoResetEvent(false); this._reqDataThreads[i] = new ThreadEx(this.ReqDataThreadMethod, $"请求数据线程[{i}]", true); this._reqDataThreads[i].Start(this._reqDataThreadsEventHandles[i]); } this._revTimeoutCheckThread = new ThreadEx(this.RevTimeoutCheckThreadMethod, "接收超时检测线程", true); this._revTimeoutCheckThread.Start(); }
public TransferSender(ITransferNet net, ResoucesInfo resoucesInfo) { this._net = net; this._resoucesInfo = resoucesInfo; }