protected NetBase(NetConfiguration config) { Debug.Assert(config != null, "Config must not be null"); if (string.IsNullOrEmpty(config.ApplicationIdentifier)) throw new ArgumentException("Must set ApplicationIdentifier in NetConfiguration!"); m_config = config; m_receiveBuffer = new NetBuffer(config.ReceiveBufferSize); m_sendBuffer = new NetBuffer(config.SendBufferSize); m_senderRemote = (EndPoint)new IPEndPoint(IPAddress.Any, 0); m_statistics = new NetBaseStatistics(); m_receivedMessages = new NetQueue<IncomingNetMessage>(4); m_scratchBuffer = new NetBuffer(32); m_bindLock = new object(); m_discovery = new NetDiscovery(this); m_randomIdentifier = new byte[8]; NetRandom.Instance.NextBytes(m_randomIdentifier); m_unsentOutOfBandMessages = new NetQueue<NetBuffer>(); m_unsentOutOfBandRecipients = new NetQueue<IPEndPoint>(); m_susmQueue = new Queue<SUSystemMessage>(); // default enabled message types m_enabledMessageTypes = NetMessageType.Data | NetMessageType.StatusChanged | NetMessageType.ServerDiscovered | NetMessageType.DebugMessage | NetMessageType.Receipt; }
public AsyncNet(string url, int method, string updateTime, int cb_addr, int context) { this.url = url; this.method = method; this.updateTime = updateTime; this.cb_addr = cb_addr; this.context = context; try { if (c_do_async_connect_cb == 0) { c_do_async_connect_cb = CibylCallTable.getAddressByName("do_async_connect_cb"); c_input_ready_cb = CibylCallTable.getAddressByName("roadmap_main_input_ready"); } } catch (Exception e) { Logger.log("Exception in do_async_connect_cb: " + e.ToString()); throw; //todomt //Environment.Exit(0); } if (queue == null) { // assumes that this is called async queue = new NetQueue(); queue.init(); } queue.add(this); }
internal NetUnreliableSenderChannel(NetConnection connection, int windowSize) { m_connection = connection; m_windowSize = windowSize; m_windowStart = 0; m_sendStart = 0; m_receivedAcks = new NetBitVector(NetConstants.NumSequenceNumbers); m_queuedSends = new NetQueue<NetOutgoingMessage>(8); }
internal NetReliableSenderChannel(NetConnection connection, int windowSize) { m_connection = connection; m_windowSize = windowSize; m_windowStart = 0; m_sendStart = 0; m_receivedAcks = new NetBitVector(NetConstants.NumSequenceNumbers); m_storedMessages = new NetStoredReliableMessage[m_windowSize]; m_queuedSends = new NetQueue<NetOutgoingMessage>(8); m_resendDelay = m_connection.GetResendDelay(); }
private SESSION_STATUS m_cStatus; //会话状态 #endregion Fields #region Constructors public SeverSession(Socket socket, DispatchFactoryBase dispatchFactory) { this.m_cDispatchFactory = dispatchFactory; this.m_cDispatch = this.m_cDispatchFactory.Create( this ); this.m_cSocket = socket; this.m_cReceiveBuffer = new StreamBuffer(); this.m_cSendBuffer = new StreamBuffer(); this.m_cSendQueue = new NetQueue<PacketBase>(64 * 256); this.m_cSendQueue.Clear(); }
internal NetConnection(NetPeer peer, IPEndPoint remoteEndpoint) { m_peer = peer; m_peerConfiguration = m_peer.Configuration; m_status = NetConnectionStatus.None; m_visibleStatus = NetConnectionStatus.None; m_remoteEndpoint = remoteEndpoint; m_sendChannels = new NetSenderChannelBase[NetConstants.NumTotalChannels]; m_receiveChannels = new NetReceiverChannelBase[NetConstants.NumTotalChannels]; m_queuedAcks = new NetQueue<NetTuple<NetMessageType, int>>(4); m_statistics = new NetConnectionStatistics(this); m_averageRoundtripTime = -1.0f; }
internal NetUnreliableSenderChannel(NetConnection connection, int windowSize, NetDeliveryMethod method) { m_connection = connection; m_windowSize = windowSize; m_windowStart = 0; m_sendStart = 0; m_receivedAcks = new NetBitVector(NetConstants.NumSequenceNumbers); m_queuedSends = new NetQueue<NetOutgoingMessage>(8); m_doFlowControl = true; if (method == NetDeliveryMethod.Unreliable && connection.Peer.Configuration.SuppressUnreliableUnorderedAcks == true) m_doFlowControl = false; }
/// <summary> /// NetPeer constructor /// </summary> public NetPeer(NetPeerConfiguration config) { m_configuration = config; m_statistics = new NetPeerStatistics(this); m_releasedIncomingMessages = new NetQueue<NetIncomingMessage>(4); m_unsentUnconnectedMessages = new NetQueue<NetTuple<NetEndPoint, NetOutgoingMessage>>(2); m_connections = new List<NetConnection>(); m_connectionLookup = new Dictionary<NetEndPoint, NetConnection>(); m_handshakes = new Dictionary<NetEndPoint, NetConnection>(); m_senderRemote = (EndPoint)new NetEndPoint(IPAddress.Any, 0); m_status = NetPeerStatus.NotRunning; m_receivedFragmentGroups = new Dictionary<NetConnection, Dictionary<int, ReceivedFragmentGroup>>(); }
private string m_strAddress; //连接地址 #endregion Fields #region Constructors public ClientSession( DispatchFactoryBase dispatchFactory ) { this.m_cStatus = SESSION_STATUS.NO_CONNECT; this.m_cDispatchFactory = dispatchFactory; this.m_cReceiveBuffer = new StreamBuffer(); this.m_cSendBuffer = new StreamBuffer(); this.m_cSendQueue = new NetQueue<PacketBase>(64 * 256); this.m_cSendQueue.Clear(); this.m_bStartReConnect = false; }
/// <summary> /// Tworzy modul zarzadzajacy polaczeniami /// </summary> /// <param name = "netModule"></param> public NetworkManager(NetworkModule netModule) { _netModule = netModule; _netQueue = netModule.netQueue; _loopback = new LocalPeer(_netModule); //_loopback.ObjectReceived += ObjectReceived; _userConnectionMap = new UserConnectionMap(_netModule); _connectThread = new ConnectThread(); // _netQueue.Register(typeof (NetworkSend), HandleNetworkSend); _networkConnectTimer = new Timer(NextConnect, null, Timeout.Infinite, Timeout.Infinite); }
internal NetUnreliableSenderChannel(NetConnection connection, int windowSize, NetDeliveryMethod method) { m_connection = connection; m_windowSize = windowSize; m_windowStart = 0; m_sendStart = 0; m_receivedAcks = new NetBitVector(NetConstants.NumSequenceNumbers); m_queuedSends = new NetQueue <NetOutgoingMessage>(8); m_doFlowControl = true; if (method == NetDeliveryMethod.Unreliable && connection.Peer.Configuration.SuppressUnreliableUnorderedAcks == true) { m_doFlowControl = false; } }
private void InitializePools() { if (m_configuration.UseMessageRecycling) { m_storagePool = new List<byte[]>(16); m_outgoingMessagesPool = new NetQueue<NetOutgoingMessage>(4); m_incomingMessagesPool = new NetQueue<NetIncomingMessage>(4); } else { m_storagePool = null; m_outgoingMessagesPool = null; m_incomingMessagesPool = null; } }
internal NetConnection(NetPeer peer, NetEndPoint remoteEndPoint) { m_peer = peer; m_peerConfiguration = m_peer.Configuration; m_status = NetConnectionStatus.None; m_outputtedStatus = NetConnectionStatus.None; m_visibleStatus = NetConnectionStatus.None; m_remoteEndPoint = remoteEndPoint; m_sendChannels = new NetSenderChannelBase[NetConstants.NumTotalChannels]; m_receiveChannels = new NetReceiverChannelBase[NetConstants.NumTotalChannels]; m_queuedOutgoingAcks = new NetQueue<NetTuple<NetMessageType, int>>(4); m_queuedIncomingAcks = new NetQueue<NetTuple<NetMessageType, int>>(4); m_statistics = new NetConnectionStatistics(this); m_averageRoundtripTime = -1.0f; m_currentMTU = m_peerConfiguration.MaximumTransmissionUnit; }
internal NetConnection(NetPeer peer, NetEndPoint remoteEndPoint) { m_peer = peer; m_peerConfiguration = m_peer.Configuration; m_status = NetConnectionStatus.None; m_outputtedStatus = NetConnectionStatus.None; m_visibleStatus = NetConnectionStatus.None; m_remoteEndPoint = remoteEndPoint; m_sendChannels = new NetSenderChannelBase[NetConstants.NumTotalChannels]; m_receiveChannels = new NetReceiverChannelBase[NetConstants.NumTotalChannels]; m_queuedOutgoingAcks = new NetQueue <NetTuple <NetMessageType, int> >(4); m_queuedIncomingAcks = new NetQueue <NetTuple <NetMessageType, int> >(4); m_statistics = new NetConnectionStatistics(this); m_averageRoundtripTime = -1.0f; m_currentMTU = m_peerConfiguration.MaximumTransmissionUnit; }
/// <summary> /// Tworzy modul sieciowy /// </summary> public NetworkModule() { Processor proc = ServiceModule.CreateProcessor(); AssignProcessor(ServiceModule, proc); netQueue = new NetQueue(ServiceModule, proc); netQueue.Start(); _interfaceLink = new InterfaceModuleLink(this); _fileLink = new FileModulelLink(this); NetworkManager = new NetworkManager(this); TaskCenter = new TaskCenter(this); _networkState = new StateDisconnected(this); }
private void InitializePools() { m_storageSlotsUsedCount = 0; if (m_configuration.UseMessageRecycling) { m_storagePool = new List<byte[]>(16); m_outgoingMessagesPool = new NetQueue<NetOutgoingMessage>(4); m_incomingMessagesPool = new NetQueue<NetIncomingMessage>(4); } else { m_storagePool = null; m_outgoingMessagesPool = null; m_incomingMessagesPool = null; } m_maxCacheCount = m_configuration.RecycledCacheMaxCount; }
internal NetConnection(NetBase owner, IPEndPoint remoteEndPoint, byte[] localHailData, byte[] remoteHailData) { m_owner = owner; m_remoteEndPoint = remoteEndPoint; m_localHailData = localHailData; m_remoteHailData = remoteHailData; m_futureClose = double.MaxValue; m_throttleDebt = owner.m_config.m_throttleBytesPerSecond; // slower start m_statistics = new NetConnectionStatistics(this, 1.0f); m_unsentMessages = new NetQueue<OutgoingNetMessage>(6); m_lockedUnsentMessages = new NetQueue<OutgoingNetMessage>(3); m_status = NetConnectionStatus.Connecting; // to prevent immediate removal on heartbeat thread InitializeReliability(); InitializeFragmentation(); InitializeStringTable(); //InitializeCongestionControl(32); }
public override void StartServer(F3_ServerConfig serverConfig) { m_consoleOuputMsg = new NetQueue<string>(16); m_registeredServers = new Dictionary<long, F3_NetServerInfo>(); base.StartServer(serverConfig); }
public Worker(NetQueue netqueue) { this.netQueue = netqueue; }
static void Main(string[] args) { GCLatencyMode oldMode = GCSettings.LatencyMode; RuntimeHelpers.PrepareConstrainedRegions(); GCSettings.LatencyMode = GCLatencyMode.Batch; ServicePointManager.DefaultConnectionLimit = int.MaxValue; GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced); DownloadQueue = new NetQueue(800); Console.WriteLine("Robust Arcalive Image Downloader"); Console.WriteLine("Copyright 2020. "); Console.Write("prefix> "); string prefix = Console.ReadLine().Trim(); Console.Write("category> "); string category = Console.ReadLine().Trim(); Console.Write("maxpage> "); int page = Convert.ToInt32(Console.ReadLine().Trim()); var urls = Enumerable.Range(1, page).Select(x => $"{prefix}?category={category}&p={x}").ToList(); Console.Write("download pages... "); List <string> htmls; { int complete = 0; using (var pb = new ExtractingProgressBar()) { htmls = NetTools.DownloadStrings(urls, "", () => { pb.Report(urls.Count, Interlocked.Increment(ref complete)); }).Result; } } var rr = new Regex(@"<a class=""vrow"" href=""(.*?)"""); var subPages = new ConcurrentBag <List <string> >(); var host = new Uri(prefix).Host; Parallel.ForEach(htmls, (html) => { subPages.Add(rr.Matches(html).Cast <Match>().Select(x => $"https://{host}{x.Groups[1].Value}").ToList()); }); Console.WriteLine($"{subPages.Sum(x=>x.Count):#,#} page loaded"); Console.Write("download article... "); var subPagesList = subPages.SelectMany(x => x).ToList(); List <string> subHtmls; { int complete = 0; using (var pb = new ExtractingProgressBar()) { subHtmls = NetTools.DownloadStrings(subPagesList, "", () => { pb.Report(subPagesList.Count, Interlocked.Increment(ref complete)); }).Result; } } Console.WriteLine("complete"); // url, path var images = new ConcurrentBag <List <(string, string)> >(); Console.Write("extracting contents... "); { int complete = 0; using (var pb = new ExtractingProgressBar()) { Parallel.ForEach(subHtmls, (html) => { var imgs = new List <(string, string)>(); var doc = new HtmlDocument(); doc.LoadHtml(html); var id = doc.DocumentNode.SelectSingleNode("//link[@rel='canonical']").GetAttributeValue("href", "").Split('/').Last(); var body = doc.DocumentNode.SelectSingleNode("//div[@class='article-body']"); var imgnodes = body.SelectNodes(".//img"); if (imgnodes != null) { foreach (var img in imgnodes) { var src = img.GetAttributeValue("src", ""); imgs.Add(($"https:{src}?type=orig", $"download/[{id}] {imgs.Count:00}." + src.Split('.').Last())); } } var videonodes = body.SelectNodes(".//video"); if (videonodes != null) { foreach (var video in body.SelectNodes(".//video")) { var src = video.GetAttributeValue("src", ""); if (video.GetAttributeValue("data-orig", "") == "gif") { imgs.Add(($"https:{src}.gif?type=orig", $"download/[{id}] {imgs.Count:00}." + "gif")); } else { imgs.Add(($"https:{src}?type=orig", $"download/[{id}] {imgs.Count:00}." + src.Split('.').Last())); } } } images.Add(imgs); pb.Report(subHtmls.Count, Interlocked.Increment(ref complete)); });
public Worker(NetQueue netqueue) { netqueue.SetWorker(this); }
public static void Run() { NetQueue<int> queue = new NetQueue<int>(4); queue.Enqueue(1); queue.Enqueue(2); queue.Enqueue(3); int[] arr = queue.ToArray(); if (arr.Length != 3) throw new Exception("NetQueue.ToArray failure"); if (arr[0] != 1 || arr[1] != 2 || arr[2] != 3) throw new Exception("NetQueue.ToArray failure"); bool ok; int a; if (queue.Contains(4)) throw new Exception("NetQueue Contains failure"); if (!queue.Contains(2)) throw new Exception("NetQueue Contains failure 2"); if (queue.Count != 3) throw new Exception("NetQueue failed"); ok = queue.TryDequeue(out a); if (ok == false || a != 1) throw new Exception("NetQueue failure"); if (queue.Count != 2) throw new Exception("NetQueue failed"); queue.EnqueueFirst(42); if (queue.Count != 3) throw new Exception("NetQueue failed"); ok = queue.TryDequeue(out a); if (ok == false || a != 42) throw new Exception("NetQueue failed"); ok = queue.TryDequeue(out a); if (ok == false || a != 2) throw new Exception("NetQueue failed"); ok = queue.TryDequeue(out a); if (ok == false || a != 3) throw new Exception("NetQueue failed"); ok = queue.TryDequeue(out a); if (ok == true) throw new Exception("NetQueue failed"); ok = queue.TryDequeue(out a); if (ok == true) throw new Exception("NetQueue failed"); queue.Enqueue(78); if (queue.Count != 1) throw new Exception("NetQueue failed"); ok = queue.TryDequeue(out a); if (ok == false || a != 78) throw new Exception("NetQueue failed"); queue.Clear(); if (queue.Count != 0) throw new Exception("NetQueue.Clear failed"); int[] arr2 = queue.ToArray(); if (arr2.Length != 0) throw new Exception("NetQueue.ToArray failure"); Console.WriteLine("NetQueue tests OK"); }
public void TestScenario() { NetQueue <int> queue = new NetQueue <int>(4); queue.Enqueue(1); queue.Enqueue(2); queue.Enqueue(3); int[] arr = queue.ToArray(); if (arr.Length != 3) { throw new Exception("NetQueue.ToArray failure"); } if (arr[0] != 1 || arr[1] != 2 || arr[2] != 3) { throw new Exception("NetQueue.ToArray failure"); } bool ok; int a; if (queue.Contains(4)) { throw new Exception("NetQueue Contains failure"); } if (!queue.Contains(2)) { throw new Exception("NetQueue Contains failure 2"); } if (queue.Count != 3) { throw new Exception("NetQueue failed"); } ok = queue.TryDequeue(out a); if (ok == false || a != 1) { throw new Exception("NetQueue failure"); } if (queue.Count != 2) { throw new Exception("NetQueue failed"); } queue.EnqueueFirst(42); if (queue.Count != 3) { throw new Exception("NetQueue failed"); } ok = queue.TryDequeue(out a); if (ok == false || a != 42) { throw new Exception("NetQueue failed"); } ok = queue.TryDequeue(out a); if (ok == false || a != 2) { throw new Exception("NetQueue failed"); } ok = queue.TryDequeue(out a); if (ok == false || a != 3) { throw new Exception("NetQueue failed"); } ok = queue.TryDequeue(out a); if (ok == true) { throw new Exception("NetQueue failed"); } ok = queue.TryDequeue(out a); if (ok == true) { throw new Exception("NetQueue failed"); } queue.Enqueue(78); if (queue.Count != 1) { throw new Exception("NetQueue failed"); } ok = queue.TryDequeue(out a); if (ok == false || a != 78) { throw new Exception("NetQueue failed"); } queue.Clear(); if (queue.Count != 0) { throw new Exception("NetQueue.Clear failed"); } int[] arr2 = queue.ToArray(); if (arr2.Length != 0) { throw new Exception("NetQueue.ToArray failure"); } }
protected Dictionary<int, HandlerBase> m_mapHandlers = new Dictionary<int,HandlerBase>(); //句柄 #endregion Fields #region Constructors public Dispatch() { this.m_cReceiveQueue = new NetQueue<PacketBase>(64 * 256); this.m_cReceiveQueue.Clear(); }
public override void StartServer(F3_ServerConfig serverConfig) { m_messages = new NetQueue<F3_ChatLine>(16); m_commands = new NetQueue<NetCommand>(16); m_registeredGroups = new Dictionary<string, List<long>>(); base.StartServer(serverConfig); }
public static void Run() { { var queue = new NetQueue <int>(4); queue.Enqueue(1); queue.Enqueue(2); queue.Enqueue(3); var arr = new int[queue.Count]; queue.CopyTo(arr); if (arr.Length != 3) { throw new Exception("NetQueue.CopyTo failure"); } if (arr[0] != 1 || arr[1] != 2 || arr[2] != 3) { throw new Exception("NetQueue.CopyTo failure"); } bool ok; if (queue.Contains(4)) { throw new Exception("NetQueue Contains failure"); } if (!queue.Contains(2)) { throw new Exception("NetQueue Contains failure 2"); } if (queue.Count != 3) { throw new Exception("NetQueue failed"); } ok = queue.TryDequeue(out int a); if (ok == false || a != 1) { throw new Exception("NetQueue failure"); } if (queue.Count != 2) { throw new Exception("NetQueue failed"); } queue.EnqueueFirst(42); if (queue.Count != 3) { throw new Exception("NetQueue failed"); } ok = queue.TryDequeue(out a); if (ok == false || a != 42) { throw new Exception("NetQueue failed"); } ok = queue.TryDequeue(out a); if (ok == false || a != 2) { throw new Exception("NetQueue failed"); } ok = queue.TryDequeue(out a); if (ok == false || a != 3) { throw new Exception("NetQueue failed"); } ok = queue.TryDequeue(out a); if (ok == true) { throw new Exception("NetQueue failed"); } ok = queue.TryDequeue(out a); if (ok == true) { throw new Exception("NetQueue failed"); } queue.Enqueue(78); if (queue.Count != 1) { throw new Exception("NetQueue failed"); } ok = queue.TryDequeue(out a); if (ok == false || a != 78) { throw new Exception("NetQueue failed"); } queue.Clear(); if (queue.Count != 0) { throw new Exception("NetQueue.Clear failed"); } int[] arr2 = new int[queue.Count]; queue.CopyTo(arr2); if (arr2.Length != 0) { throw new Exception("NetQueue.CopyTo failure"); } } { var queue = new NetQueue <int>(8); queue.Enqueue(1); queue.Enqueue(2); queue.Enqueue(3); queue.EnqueueFirst(4); List <int> destination = new(); int drained = queue.TryDrain(destination); if (destination.Count != drained) { throw new Exception("NetQueue.TryDrain drained incorrect amount"); } } Console.WriteLine("NetQueue tests OK"); }