Example #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());
        }
Example #2
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);
        }