Exemple #1
0
        private void HandleRawRead(IEnumerable <Part> Parts, Action <StreamedVirtualTransportServerHandleResult[]> OnSuccess, Action OnFailure)
        {
            if (ssm.IsExited())
            {
                return;
            }
            var Results = new List <StreamedVirtualTransportServerHandleResult>();

            foreach (var p in Parts)
            {
                var Buffer       = vts.GetReadBuffer();
                var BufferLength = Buffer.Offset + Buffer.Count;
                if (p.Data.Length > Buffer.Array.Length - BufferLength)
                {
                    OnFailure();
                    return;
                }
                Array.Copy(p.Data, 0, Buffer.Array, BufferLength, p.Data.Length);

                var c = p.Data.Length;
                while (true)
                {
                    StreamedVirtualTransportServerHandleResult Result;
                    try
                    {
                        Result = vts.Handle(c);
                    }
                    catch (Exception ex)
                    {
                        if ((ex is InvalidOperationException) && (ex.Message != ""))
                        {
                            Server.ServerContext.RaiseSessionLog(new SessionLogEntry {
                                Token = Context.SessionTokenString, RemoteEndPoint = RemoteEndPoint, Time = DateTime.UtcNow, Type = "Known", Name = "Exception", Message = ex.Message
                            });
                        }
                        else if (!IsSocketErrorKnown(ex))
                        {
                            OnCriticalError(ex, new StackTrace(true));
                        }
                        OnFailure();
                        return;
                    }
                    c = 0;
                    if (Result.OnContinue)
                    {
                        break;
                    }
                    Results.Add(Result);
                }
            }
            if (Results.Count == 0)
            {
                OnStartRawRead(OnSuccess, OnFailure);
                return;
            }
            OnSuccess(Results.ToArray());
        }
Exemple #2
0
        public void Dispose()
        {
            if (IsDisposed)
            {
                return;
            }
            IsDisposed = true;

            IsExitingValue.Update(b => true);
            ssm.NotifyExit();

            Server.SessionMappings.DoAction(Mappings =>
            {
                if (Mappings.ContainsKey(Context))
                {
                    Mappings.Remove(Context);
                }
            });
            Server.ServerContext.TryUnregisterSession(Context);

            si.Dispose();

            IsRunningValue.Update(b => false);

            SpinWait.SpinUntil(() => ssm.IsExited());

            Context.Dispose();

            IsExitingValue.Update(b => false);

            if (Server.ServerContext.EnableLogSystem)
            {
                Server.ServerContext.RaiseSessionLog(new SessionLogEntry {
                    Token = Context.SessionTokenString, RemoteEndPoint = RemoteEndPoint, Time = DateTime.UtcNow, Type = "Sys", Name = "SessionExit", Message = ""
                });
            }
        }
Exemple #3
0
        private void OnStartRawRead(Action <StreamedVirtualTransportServerHandleResult[]> OnSuccess, Action OnFailure)
        {
            Action <int> Completed = Count =>
            {
                if (Count <= 0)
                {
                    OnFailure();
                    return;
                }
                if (ssm.IsExited())
                {
                    return;
                }
                var Results = new List <StreamedVirtualTransportServerHandleResult>();
                var c       = Count;
                while (true)
                {
                    StreamedVirtualTransportServerHandleResult Result;
                    try
                    {
                        Result = vts.Handle(c);
                    }
                    catch (Exception ex)
                    {
                        if ((ex is InvalidOperationException) && (ex.Message != ""))
                        {
                            Server.ServerContext.RaiseSessionLog(new SessionLogEntry {
                                Token = Context.SessionTokenString, RemoteEndPoint = RemoteEndPoint, Time = DateTime.UtcNow, Type = "Known", Name = "Exception", Message = ex.Message
                            });
                        }
                        else if (!IsSocketErrorKnown(ex))
                        {
                            OnCriticalError(ex, new StackTrace(true));
                        }
                        OnFailure();
                        return;
                    }
                    c = 0;
                    if (Result.OnContinue)
                    {
                        break;
                    }
                    Results.Add(Result);
                }
                if (Results.Count == 0)
                {
                    OnStartRawRead(OnSuccess, OnFailure);
                    return;
                }
                OnSuccess(Results.ToArray());
            };
            Action <Exception> Faulted = ex =>
            {
                if (!IsSocketErrorKnown(ex))
                {
                    OnCriticalError(ex, new StackTrace(true));
                }
                OnFailure();
            };
            var Buffer       = vts.GetReadBuffer();
            var BufferLength = Buffer.Offset + Buffer.Count;

            Socket.ReceiveAsync(Buffer.Array, BufferLength, Buffer.Array.Length - BufferLength, Completed, Faulted);
        }