Esempio n. 1
0
        /// <summary>
        /// Callback that informs us when a Link is connected.
        /// </summary>
        /// <param name="connectingLink"></param>
        /// <returns></returns>
        virtual protected VscResult LinkConnectCallback(VscLink connectingLink)
        {
            VscResult retRes = VscResult.OK;

            Log($"VS Connect Link connecting: {connectingLink.ptr.ToInt64():x}.\n");

            VsConnectNode node = VsConnectNode.GetInstanceFromLink(connectingLink);

            retRes = ShouldProcessCallback(node, connectingLink);

            return(retRes);
        }
Esempio n. 2
0
        public VsConnectNode Listen_IP(string ListenAddress
                                       , int port             = 0
                                       , int maxConnections   = 10
                                       , bool requireTimeSync = false)
        {
            ListenAddress.TrimAndUnquoteInPlace();

            VscResult createRes  = VscResult.UNDEFINED;
            var       newNodePtr = vsc_Api_V3_t.Node_Create_UDPIP(ListenAddress
                                                                  , (ushort)port
                                                                  , maxConnections
                                                                  , requireTimeSync ?   VscTimeSyncMode.ABSOLUTE : VscTimeSyncMode.NONE
                                                                  , linkConnectCallback
                                                                  , linkdisconnectCallback
                                                                  , contractRequestCallback
                                                                  , contractCanceledCallback
                                                                  , sendUpdateCallback
                                                                  , receiveUpdateCallback
                                                                  , null
                                                                  , ref createRes
                                                                  );


            if (newNodePtr != IntPtr.Zero)
            {
                var newNode = new VsConnectNode(newNodePtr);
                vsc_Api_V3_t.Node_SetAppData(newNode.VscNode, ToPtr(newNode));

                Log(("Successfully created VS Connect Server Node."));
                mVscNodes.Add(newNode);
                return(newNode);
            }
            else
            {
                LogError($"Failed to create VS Connect Server Node: {ListenAddress}:{port}");
                return(null);
            }
        }
Esempio n. 3
0
        virtual protected void DisconnectAllLinks()
        {
            foreach (var node in mVscNodes)
            {
                Check(node != null);
                if (node.VscNode != IntPtr.Zero)
                {
                    int numLinks = vsc_Api_V3_t.Node_GetNumLinks(node.VscNode);

                    for (int i = 0; i < numLinks; ++i)
                    {
                        VscLink link = vsc_Api_V3_t.Node_GetLink(node.VscNode, i);
                        Check(link != IntPtr.Zero);
                        Check(vsc_Api_V3_t.Link_GetConnectionStatus(link) != VscConnectionStatus.UNCONNECTED);
                        VscResult disconnectRes = vsc_Api_V3_t.Link_Disconnect(link);
                        //check(!vsc_IsError(disconnectRes));
                    }
                }
            }

            bool  done    = false;
            float timeout = 5.0f;

            while (!done && timeout > 0)
            {
                done = true;  // We're done unless we find a Node with Links that are not disconnected.

                foreach (var node in mVscNodes)
                {
                    Check(node != null);

                    if (node.VscNode != IntPtr.Zero)
                    {
                        vsc_Api_V3_t.Node_Service(node.VscNode, vsc_Api_V3_t.GetInvalidSimtime(), vsc_Api_V3_t.GetInvalidSimtime(), true);
                    }
                }

                foreach (var node in mVscNodes)
                {
                    Check(node != null);

                    if (node.VscNode != IntPtr.Zero)
                    {
                        if (0 == vsc_Api_V3_t.Node_GetNumLinks(node.VscNode))
                        {
                        }
                        else
                        {
                            done = false;
                            vsc_Api_V3_t.Node_Service(node.VscNode, vsc_Api_V3_t.GetInvalidSimtime(), vsc_Api_V3_t.GetInvalidSimtime(), true);
                        }
                    }
                }

                if (!done)
                {
                    const float sleepTime = 0.100f;  ///< Seconds to sleep during each iteration while disconnecting.
                    System.Threading.Thread.Sleep((int)(1000 * sleepTime));
                    timeout -= sleepTime;
                }
            }
        }