示例#1
0
        void Setup()
        {
            if (IsInited == true)
            {
                return;
            }
            for (int i = 0; i < 10; ++i)
            {
                SendMessage(setupCmds[i]);
                Thread.Sleep(10);
            }

            packetNum = 0;

            for (int i = 10; i < setupCmds.Count; ++i)
            {
                SendMessage(setupCmds[i]);
                Thread.Sleep(10);
            }
            IsInited = true;
            if (InitDone != null)
            {
                InitDone.Invoke(this, null);
            }
        }
示例#2
0
        public void AddSessionObj(KServerSession serverSession, IpcService obj)
        {
            // Ensure that the sever loop is running.
            InitDone.WaitOne();

            _selfProcess.HandleTable.GenerateHandle(serverSession, out int serverSessionHandle);
            AddSessionObj(serverSessionHandle, obj);
        }
示例#3
0
    IEnumerator coGo(List <IModule> modules, InitDone callBack)
    {
        foreach (IModule curr in modules)
        {
            IEnumerator it = curr.Init();
            while (it.MoveNext())
            {
                yield return(null);
            }
        }

        callBack();
        GameObject.Destroy(this);//销毁本组件
    }
示例#4
0
        protected virtual void Dispose(bool disposing)
        {
            if (disposing)
            {
                foreach (IpcService service in _sessions.Values)
                {
                    if (service is IDisposable disposableObj)
                    {
                        disposableObj.Dispose();
                    }

                    service.DestroyAtExit();
                }

                _sessions.Clear();

                InitDone.Dispose();
            }
        }
示例#5
0
        private void ServerLoop()
        {
            _selfProcess = KernelStatic.GetCurrentProcess();

            if (SmObjectFactory != null)
            {
                _context.Syscall.ManageNamedPort("sm:", 50, out int serverPortHandle);

                AddPort(serverPortHandle, SmObjectFactory);

                InitDone.Set();
            }
            else
            {
                InitDone.Dispose();
            }

            KThread thread     = KernelStatic.GetCurrentThread();
            ulong   messagePtr = thread.TlsAddress;

            _context.Syscall.SetHeapSize(0x200000, out ulong heapAddr);

            _selfProcess.CpuMemory.Write(messagePtr + 0x0, 0);
            _selfProcess.CpuMemory.Write(messagePtr + 0x4, 2 << 10);
            _selfProcess.CpuMemory.Write(messagePtr + 0x8, heapAddr | ((ulong)PointerBufferSize << 48));

            int replyTargetHandle = 0;

            while (true)
            {
                int[] portHandles    = _portHandles.ToArray();
                int[] sessionHandles = _sessionHandles.ToArray();
                int[] handles        = new int[portHandles.Length + sessionHandles.Length];

                portHandles.CopyTo(handles, 0);
                sessionHandles.CopyTo(handles, portHandles.Length);

                // We still need a timeout here to allow the service to pick up and listen new sessions...
                var rc = _context.Syscall.ReplyAndReceive(handles, replyTargetHandle, 1000000L, out int signaledIndex);

                thread.HandlePostSyscall();

                if (!thread.Context.Running)
                {
                    break;
                }

                replyTargetHandle = 0;

                if (rc == KernelResult.Success && signaledIndex >= portHandles.Length)
                {
                    // We got a IPC request, process it, pass to the appropriate service if needed.
                    int signaledHandle = handles[signaledIndex];

                    if (Process(signaledHandle, heapAddr))
                    {
                        replyTargetHandle = signaledHandle;
                    }
                }
                else
                {
                    if (rc == KernelResult.Success)
                    {
                        // We got a new connection, accept the session to allow servicing future requests.
                        if (_context.Syscall.AcceptSession(handles[signaledIndex], out int serverSessionHandle) == KernelResult.Success)
                        {
                            IpcService obj = _ports[handles[signaledIndex]].Invoke();

                            AddSessionObj(serverSessionHandle, obj);
                        }
                    }

                    _selfProcess.CpuMemory.Write(messagePtr + 0x0, 0);
                    _selfProcess.CpuMemory.Write(messagePtr + 0x4, 2 << 10);
                    _selfProcess.CpuMemory.Write(messagePtr + 0x8, heapAddr | ((ulong)PointerBufferSize << 48));
                }
            }
        }
示例#6
0
        private void ServerLoop()
        {
            if (SmObject != null)
            {
                _context.Syscall.ManageNamedPort("sm:", 50, out int serverPortHandle);

                AddPort(serverPortHandle, SmObject);

                InitDone.Set();
            }
            else
            {
                InitDone.Dispose();
            }

            KThread thread     = _context.Scheduler.GetCurrentThread();
            ulong   messagePtr = thread.TlsAddress;

            _context.Syscall.SetHeapSize(0x200000, out ulong heapAddr);

            _selfProcess.CpuMemory.Write(messagePtr + 0x0, 0);
            _selfProcess.CpuMemory.Write(messagePtr + 0x4, 2 << 10);
            _selfProcess.CpuMemory.Write(messagePtr + 0x8, heapAddr | ((ulong)PointerBufferSize << 48));

            int replyTargetHandle = 0;

            while (true)
            {
                int[] handles = _portHandles.ToArray();

                for (int i = 0; i < handles.Length; i++)
                {
                    if (_context.Syscall.AcceptSession(handles[i], out int serverSessionHandle) == KernelResult.Success)
                    {
                        AddSessionObj(serverSessionHandle, _ports[handles[i]]);
                    }
                }

                handles = _sessionHandles.ToArray();

                var rc = _context.Syscall.ReplyAndReceive(handles, replyTargetHandle, 1000000L, out int signaledIndex);

                thread.HandlePostSyscall();

                if (!thread.Context.Running)
                {
                    break;
                }

                replyTargetHandle = 0;

                if (rc == KernelResult.Success && signaledIndex != -1)
                {
                    int signaledHandle = handles[signaledIndex];

                    if (Process(signaledHandle, heapAddr))
                    {
                        replyTargetHandle = signaledHandle;
                    }
                }
                else
                {
                    _selfProcess.CpuMemory.Write(messagePtr + 0x0, 0);
                    _selfProcess.CpuMemory.Write(messagePtr + 0x4, 2 << 10);
                    _selfProcess.CpuMemory.Write(messagePtr + 0x8, heapAddr | ((ulong)PointerBufferSize << 48));
                }
            }
        }
示例#7
0
 public void Go(List <IModule> modules, InitDone callBack)
 {
     StartCoroutine(coGo(modules, callBack));
 }