Beispiel #1
0
        private ArraySegment <byte> WrapFragment(SequenceState seqState, byte[] buffer, int offset, int length, ushort fragId, ushort fragNum, ushort fragCount, bool reliable)
        {
            var header = _headersPool.Get();

            header.SetSessionId(seqState.SessionId);
            if (reliable)
            {
                header.SetNeedAck();
            }

            ushort seqNum = seqState.NextSeqNum();

            header.SetSeqNum(seqNum);
            header.SetFrag(fragId, fragNum, fragCount);
            seqState.AddAcks(header);

            var fullBuffer = AttachHeader(buffer, offset, length, header);

            if (reliable)
            {
                AddNotAcked(seqState, seqNum, fullBuffer);
            }

            _headersPool.Put(header);

            return(fullBuffer);
        }
Beispiel #2
0
        private void SendConnectionResponse(IPEndPoint endPoint, SequenceState seqState)
        {
            var header = _headersPool.Get();

            header.SetSessionId(seqState.SessionId);
            header.SetConnect();
            header.Length = (ushort)header.HeaderLength;

            var buffer = _buffersPool.Get(header.HeaderLength);

            header.WriteTo(buffer, 0);

            var putBufferToPool = true;

            try
            {
                SubSock.Send(endPoint, buffer, 0, header.HeaderLength, putBufferToPool);
            }
            catch (SocketException)
            {
                Close(endPoint, seqState);
            }

            _headersPool.Put(header);
        }
Beispiel #3
0
        private void AddNotAcked(SequenceState seqState, ushort seqNum, ArraySegment <byte> fullBuffer)
        {
            var notAcked = new NotAckedPacket();

            notAcked.Buffer    = fullBuffer.Array;
            notAcked.Offset    = fullBuffer.Offset;
            notAcked.Length    = fullBuffer.Count;
            notAcked.SendTicks = Environment.TickCount;
            notAcked.SeqNum    = seqNum;

            seqState.AddNotAcked(notAcked);
        }
Beispiel #4
0
 private void Close(IPEndPoint endPoint, SequenceState seqState)
 {
     _seqStates.Remove(endPoint);
     _callbacks.OnDisconnect(endPoint, DisconnectReason.SocketClose);
     _seqStatesPool.Put(seqState);
 }