示例#1
0
 internal override void OnDestroy()
 {
     Cancel();
     ThreadPool.Dispose();
     GameEvents.onEditorLoad.Remove(OnVesselLoaded);
     GameEvents.onEditorNewShipDialogDismiss.Remove(OnNewVessel);
     GameEvents.onEditorPodPicked.Remove(OnRootChanged);
     base.OnDestroy();
     grapher.Dispose();
     Destroy(crossHair);
     Destroy(selectedCrossHair);
     Destroy(clearTex);
     Destroy(settingsTex);
     if (inputLocked)
     {
         EditorLogic.fetch.Unlock(lockID);
     }
 }
示例#2
0
 void ShutdownThreadPool(object sender, EventArgs e)
 {
     threadPool.Dispose();
 }
示例#3
0
 void OnDestroy()
 {
     _threadPool.Dispose();
 }
示例#4
0
        public void TestSocketServerClientThread()
        {
            var  server = SocketBase.Create <SocketServer>();
            bool rc     = server.Bind("127.0.0.1:" + port);

            Assert.IsTrue(rc);

            List <SocketBase> clientSet = new List <SocketBase>();

            for (int i = 0; i < clientCount; i++)
            {
                var client = SocketBase.Create(SocketType.Client);
                rc = client.Connect("127.0.0.1:" + port);
                Assert.IsTrue(rc);
                clientSet.Add(client);
            }

            port++;

            var checkData = generateCheckData();

            rc = Thread.Wait(() => server.ConnectionCount == clientCount, 1000);
            Assert.IsTrue(rc);

            string hello  = "Hello";
            var    writer = new ByteBufferWriter(16);

            writer.WriteString(hello);
            var helloMessage = new Message(writer);

            for (int i = 0; i < clientCount; i++)
            {
                rc = clientSet[i].TrySend(ref helloMessage, 1000);
                Assert.IsTrue(rc);
            }

            List <uint> clientIdSet = new List <uint>(clientCount);

            for (int i = 0; i < clientCount; i++)
            {
                Message msg;
                rc = server.TryRecv(out msg, 1000);
                Assert.IsTrue(rc);
                Assert.Less(0, msg.RouteId);
                Assert.IsFalse(clientIdSet.Contains(msg.RouteId));
                clientIdSet.Add(msg.RouteId);
                var reader = msg.GetBufferReader();
                var value  = reader.ReadString();
                Assert.AreEqual(value, hello);
            }

            var threadPool = new ThreadPool(clientCount);

            threadPool.Send(() => {
                for (int c = 0; c < clientCount; c++)
                {
                    for (int i = 0; i < checkCount; i++)
                    {
                        var msg = generateMessage(checkData);
                        rc      = server.Send(clientIdSet[c], ref msg);
                        Assert.IsTrue(rc, "client id: " + clientIdSet[c] + ", message id: " + i);
                    }
                }
            });

            int result = 0;

            for (int c = 0; c < clientCount; c++)
            {
                var client   = clientSet[c];
                var clientId = clientIdSet[c];
                threadPool.Post(() => {
                    for (int i = 0; i < checkCount; i++)
                    {
                        Message msg;
                        rc = client.Recv(out msg);
                        Assert.IsTrue(rc, "client id: " + clientId + ", message id: " + i);
                        checkMessage(ref msg, checkData);
                        Atomic.Inc(ref result);
                    }
                });
            }

            rc = Thread.Wait(() => result == clientCount * checkCount, -1);
            Assert.IsTrue(rc);

            threadPool.Dispose();
            Assert.AreEqual(result, clientCount * checkCount);

            for (int i = 0; i < clientSet.Count; i++)
            {
                clientSet[i].Close();
                rc = clientSet[i].WaitClose(1000);
                Assert.IsTrue(rc);
            }

            server.Close();
            rc = server.WaitClose(1000);
            Assert.IsTrue(rc);
        }
示例#5
0
        public void TestSocketPubSubMultiple()
        {
            List <SocketBase> pubSet = new List <SocketBase>();

            for (int i = 0; i < serverCount; i++)
            {
                var  pub = SocketBase.Create(SocketType.Pub);
                bool rc  = pub.Bind("127.0.0.1:" + (port + i));
                Assert.IsTrue(rc);
                pubSet.Add(pub);
            }

            List <SocketBase> subSet = new List <SocketBase>();

            for (int i = 0; i < clientCount; i++)
            {
                var sub = SocketBase.Create(SocketType.Sub);
                for (int p = 0; p < serverCount; p++)
                {
                    bool rc = sub.Connect("127.0.0.1:" + (port + p));
                    Assert.IsTrue(rc);
                }
                subSet.Add(sub);
            }

            port += serverCount;

            var checkData = generateCheckData();

            var threadPool = new ThreadPool(clientCount);

            for (int p = 0; p < serverCount; p++)
            {
                var pub = pubSet[p];
                threadPool.Post(() => {
                    bool rc = Thread.Wait(() => pub.ConnectionCount == clientCount, 1000);
                    Assert.IsTrue(rc);
                    for (int i = 0; i < checkCount; i++)
                    {
                        var msg = generateMessage(checkData);
                        rc      = pub.TrySend(ref msg, 1000);
                        Assert.IsTrue(rc);
                    }
                });
            }

            int result = 0;

            for (int s = 0; s < clientCount; s++)
            {
                var sub   = subSet[s];
                var subId = s;
                threadPool.Post(() => {
                    bool rc = Thread.Wait(() => sub.ConnectionCount == serverCount, 1000);
                    Assert.IsTrue(rc);
                    for (int i = 0; i < checkCount * serverCount; i++)
                    {
                        Message msg;
                        rc = sub.TryRecv(out msg, 1000);
                        Assert.IsTrue(rc, "message id: " + i + ", sub id: " + subId);
                        checkMessage(ref msg, checkData);
                        Atomic.Inc(ref result);
                    }
                });
            }

            bool ret = Thread.Wait(() => result == clientCount * checkCount * serverCount, 10000);

            Assert.IsTrue(ret);

            threadPool.Dispose();
            Assert.AreEqual(result, clientCount * checkCount * serverCount);

            for (int i = 0; i < subSet.Count; i++)
            {
                subSet[i].Close();
                bool rc = subSet[i].WaitClose(1000);
                Assert.IsTrue(rc);
            }

            for (int i = 0; i < pubSet.Count; i++)
            {
                pubSet[i].Close();
                bool rc = pubSet[i].WaitClose(1000);
                Assert.IsTrue(rc);
            }
        }
示例#6
0
        public void TestSocketPubSubThread()
        {
            var  pub = SocketBase.Create(SocketType.Pub);
            bool rc  = pub.Bind("127.0.0.1:" + port);

            Assert.IsTrue(rc);

            List <SocketBase> subSet = new List <SocketBase>();

            for (int i = 0; i < clientCount; i++)
            {
                var sub = SocketBase.Create(SocketType.Sub);
                rc = sub.Connect("127.0.0.1:" + port);
                Assert.IsTrue(rc);
                subSet.Add(sub);
            }

            port++;

            var checkData = generateCheckData();

            var threadPool = new ThreadPool(clientCount);

            threadPool.Post(() => {
                rc = Thread.Wait(() => pub.ConnectionCount == clientCount, 1000);
                Assert.IsTrue(rc);
                for (int i = 0; i < checkCount; i++)
                {
                    var msg = generateMessage(checkData);
                    rc      = pub.TrySend(ref msg, 1000);
                    Assert.IsTrue(rc);
                }
            });

            int result = 0;

            for (int c = 0; c < clientCount; c++)
            {
                var sub = subSet[c];
                threadPool.Post(() => {
                    rc = Thread.Wait(() => sub.ConnectionCount == 1, 1000);
                    Assert.IsTrue(rc);
                    for (int i = 0; i < checkCount; i++)
                    {
                        Message msg;
                        rc = sub.TryRecv(out msg, 1000);
                        Assert.IsTrue(rc);
                        checkMessage(ref msg, checkData);
                        Atomic.Inc(ref result);
                    }
                });
            }

            var ret = Thread.Wait(() => result == clientCount * checkCount, 10000);

            Assert.IsTrue(ret);

            threadPool.Dispose();
            Assert.AreEqual(result, clientCount * checkCount);

            for (int i = 0; i < subSet.Count; i++)
            {
                subSet[i].Close();
                rc = subSet[i].WaitClose(1000);
                Assert.IsTrue(rc);
            }

            pub.Close();
            rc = pub.WaitClose(1000);
            Assert.IsTrue(rc);
        }