Ejemplo n.º 1
0
        public KernelResult ConnectLight(out KLightClientSession clientSession)
        {
            clientSession = null;

            KProcess currentProcess = KernelContext.Scheduler.GetCurrentProcess();

            if (currentProcess.ResourceLimit != null &&
                !currentProcess.ResourceLimit.Reserve(LimitableResource.Session, 1))
            {
                return(KernelResult.ResLimitExceeded);
            }

            if (!IncrementSessionsCount())
            {
                currentProcess.ResourceLimit?.Release(LimitableResource.Session, 1);

                return(KernelResult.SessionCountExceeded);
            }

            KLightSession session = new KLightSession(KernelContext);

            KernelResult result = _parent.EnqueueIncomingLightSession(session.ServerSession);

            if (result != KernelResult.Success)
            {
                session.ClientSession.DecrementReferenceCount();
                session.ServerSession.DecrementReferenceCount();

                return(result);
            }

            clientSession = session.ClientSession;

            return(result);
        }
Ejemplo n.º 2
0
        public KernelResult ConnectLight(out KLightClientSession clientSession)
        {
            clientSession = null;

            KProcess currentProcess = System.Scheduler.GetCurrentProcess();

            if (currentProcess.ResourceLimit != null &&
                !currentProcess.ResourceLimit.Reserve(LimitableResource.Session, 1))
            {
                return(KernelResult.ResLimitExceeded);
            }

            lock (_countIncLock)
            {
                if (_sessionsCount < _maxSessions)
                {
                    _sessionsCount++;
                }
                else
                {
                    currentProcess.ResourceLimit?.Release(LimitableResource.Session, 1);

                    return(KernelResult.SessionCountExceeded);
                }
            }

            KLightSession session = new KLightSession(System);

            KernelResult result = _parent.EnqueueIncomingLightSession(session.ServerSession);

            if (result != KernelResult.Success)
            {
                session.ClientSession.DecrementReferenceCount();
                session.ServerSession.DecrementReferenceCount();

                return(result);
            }

            clientSession = session.ClientSession;

            return(result);
        }