/// <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); }
/// <summary> /// 构造函数 /// </summary> public TransferNet(TransferConfig config, IEnumerable <ushort> listenPorts, Action <ReceiveDataItem> rev) { if (listenPorts == null || listenPorts.Count() == 0) { throw new ArgumentNullException(nameof(listenPorts)); } if (rev == null) { throw new ArgumentNullException(nameof(rev)); } if (config == null) { config = new TransferConfig(); } else { config.Validate(); } this._revQueue = new AsynQueue <ReceiveDataItem>(rev, "TransferNet.接收数据输出线程", true, true); try { foreach (var listenPort in listenPorts) { TransferConfig config2 = config.Clone(); config2.NetConfig.ListenEP = new IPEndPoint(IPAddress.Any, listenPort); this._transferChannels.Add(new UdpTransferChannelItem(new TransferChannel(config2, this.TransferChannelRev))); } } catch (Exception) { this.Dispose(); throw; } }
public TransferParaAnalyze(TransferConfig config) { this._config = config; ushort detectStepLength = config.DetectStepLength; ushort stepDetectCount = config.StepDetectCount; int mtuRange = TransferConstant.MTU_MAX - TransferConstant.MTU_MIN; int count = mtuRange / detectStepLength; if (mtuRange % detectStepLength > 0) { count += 1; } this._netInfoMaxCount = count * config.StepDetectCount; this._netTransferParas = new NetTransferPara[this._netInfoMaxCount]; for (int i = 0; i < this._netInfoMaxCount; i++) { this._netTransferParas[i] = new NetTransferPara(); } this._durationAdjustMtuMaxCount = (mtuRange / config.MtuFineTuning) / 2; }
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 static void Init(TransferConfig config) { _config = config; }