コード例 #1
0
        public static void Shutdown()
        {
            if (!serviceInitialized)
            {
                return;
            }

#if ENABLE_MULTICAST
            Multicast.Shutdown();
#endif
            Disconnect();

            ShutdownMessageStreamManager();

            receiveStream.Free();
            PlatformShutdown();

            serviceInitialized = false;
        }
コード例 #2
0
        public static void TransmitAndReceive()
        {
#if ENABLE_MULTICAST
            Multicast.Broadcast();
#endif
            Connect();

            if (!Connected)
            {
                if (state == ConnectionState.Invalid)
                {
                    MessageStreamManager.RecycleAll();
                }
                return;
            }

            // Check if got disconnected
#if UNITY_WEBGL
            if (WebSocketLostConnection() == 1)
#else
            Baselib_Socket_PollFd pollFd = new Baselib_Socket_PollFd();
            unsafe
            {
                pollFd.handle.handle   = hSocket.handle;
                pollFd.errorState      = (Baselib_ErrorState *)UnsafeUtility.AddressOf(ref errState);
                pollFd.requestedEvents = Baselib_Socket_PollEvents.Connected;

                Baselib_Socket_Poll(&pollFd, 1, 0, (Baselib_ErrorState *)UnsafeUtility.AddressOf(ref errState));
            };

            if (errState.code != Baselib_ErrorCode.Success)
#endif
            {
                Disconnect();
                return;
            }

            // Disconnection didn't occur, but we could still be waiting on a connection
#if UNITY_WEBGL
            if (WebSocketIsConnecting() == 1)
#else
            if (pollFd.resultEvents != Baselib_Socket_PollEvents.Connected)
#endif
            {
                return;
            }

#if ENABLE_PROFILER
            // While the profiler is generally lock-free, this ensures no new threads or markers are initialized and used
            // after sending the session stream (which contains the identification for new threads and markers)
            // but just before sending the related stream using this new thread or marker. The timing is pretty specific
            // but does happen - especially with threads unsynchronized from the main thread - such as the render thread.
            //
            // This will not have any performance implications once a marker or thread is intialized so typically we'll
            // stall for a couple microseconds on, say, the first frame or two and then no longer have contention.
            Profiler.PlayerConnectionMt_LockProfilerHashTables();

            ProfilerProtocolSession.SendNewMarkersAndThreads();
            ProfilerProtocolSession.SendProfilerStats();

            // Calculated per frame
            ProfilerStats.GatheredStats = ProfilerModes.ProfileDisabled;

            unsafe
            {
                // It's ugly here, but this needs to be before other profiler data that is sent - so we do it manually
                // and only if we know we're going to TrySubmitAll() after other checks above
                ProfilerProtocolSession.streamSession.buffer->TrySubmitStream(true);
            }
#endif
            MessageStreamManager.TrySubmitAll();
#if ENABLE_PROFILER
            Profiler.PlayerConnectionMt_UnlockProfilerHashTables();
#endif
            Receive();

            if (!Connected)
            {
                return;
            }

            Transmit();
        }
コード例 #3
0
        public static void InitializeMulticast()
        {
#if ENABLE_MULTICAST
            Multicast.Initialize(initType == ConnectionState.ConnectDirect, initPort);
#endif
        }
コード例 #4
0
        // This is separate from the default initialization because it depends on configuration data which is not loaded until after
        // core systems have been initialized. Configuration data lives in the ECS world.
        public static void InitializeMulticast(uint editorGuid32, string gameName)
        {
#if ENABLE_MULTICAST
            Multicast.Initialize(initType == ConnectionState.ConnectDirect, initPort, editorGuid32, gameName);
#endif
        }