public Boolean Push(IPEndPoint RemoteEndPoint, int Index, int[] Indices, Byte[] Buffer, int Offset, int Length) { var SessionId = this.SessionId; var Time = DateTime.UtcNow; if ((Indices != null) && (Indices.Length > 0)) { var l = new List <Byte[]>(); CookedWritingContext.DoAction(c => { c.Parts.Acknowledge(Indices.First(), Indices.Skip(1), c.WritenIndex); }); } { var l = new List <Byte[]>(); CookedWritingContext.DoAction(c => { c.Parts.ForEachTimedoutPacket(SessionId, Time, (i, d, ResentCount) => { l.Add(d); if (Server.ServerContext.EnableLogTransport) { Server.ServerContext.RaiseSessionLog(new SessionLogEntry { Token = SessionId.ToString("X8"), RemoteEndPoint = RemoteEndPoint, Time = DateTime.UtcNow, Type = "UdpTransport", Name = "Resend", Message = "Index: " + i.ToInvariantString() + " Length: " + d.Length.ToInvariantString() + " Count: " + ResentCount.ToInvariantString() }); } }); }); foreach (var p in l) { try { SendPacket(RemoteEndPoint, p); } catch { return(false); } } } var Pushed = false; var Parts = new List <Part>(); Action <StreamedVirtualTransportServerHandleResult[]> OnSuccess = null; Action OnFailure = null; RawReadingContext.DoAction(c => { if (c.Parts.HasPart(Index)) { Pushed = true; return; } Pushed = c.Parts.TryPushPart(Index, Buffer, Offset, Length); if (Pushed) { c.NotAcknowledgedIndices.Add(Index); var Acknowledged = new List <int>(); foreach (var i in c.NotAcknowledgedIndices) { if (c.Parts.IsEqualOrAfter(c.Parts.MaxHandled, i)) { Acknowledged.Add(i); } } foreach (var i in Acknowledged) { c.NotAcknowledgedIndices.Remove(i); } if ((c.OnSuccess != null) && (c.OnFailure != null)) { while (true) { var p = c.Parts.TryTakeFirstPart(); if (p == null) { break; } Parts.Add(p); } if (Parts.Count > 0) { OnSuccess = c.OnSuccess; OnFailure = c.OnFailure; c.OnSuccess = null; c.OnFailure = null; } } } }); if (Pushed) { LastActiveTimeValue.Update(v => DateTime.UtcNow); } if (Parts.Count > 0) { HandleRawRead(Parts, OnSuccess, OnFailure); } return(Pushed); }
public Boolean PushAux(IPEndPoint RemoteEndPoint, int[] Indices) { var SessionId = this.SessionId; var Time = DateTime.UtcNow; if ((Indices != null) && (Indices.Length > 0)) { var l = new List <Byte[]>(); CookedWritingContext.DoAction(c => { c.Parts.Acknowledge(Indices.First(), Indices.Skip(1), c.WritenIndex); }); } { var l = new List <Byte[]>(); CookedWritingContext.DoAction(c => { c.Parts.ForEachTimedoutPacket(SessionId, Time, (i, d, ResentCount) => { l.Add(d); if (Server.ServerContext.EnableLogTransport) { Server.ServerContext.RaiseSessionLog(new SessionLogEntry { Token = SessionId.ToString("X8"), RemoteEndPoint = RemoteEndPoint, Time = DateTime.UtcNow, Type = "UdpTransport", Name = "Resend", Message = "Index: " + i.ToInvariantString() + " Length: " + d.Length.ToInvariantString() + " Count: " + ResentCount.ToInvariantString() }); } }); }); foreach (var p in l) { try { SendPacket(RemoteEndPoint, p); } catch { return(false); } } } return(true); }