+ #if CACHE_FUTURE_PACKETS_IN_BYTES
+ int i, length = 0;
+ Uint32 index;
+
+ // Calculate length of contiguous bytes
+ length = Connection->HighestSequenceRcvd - Connection->NextSequenceRcv;
+ index = Connection->NextSequenceRcv % TCP_WINDOW_SIZE;
+ for( i = 0; i < length; i ++ )
+ {
+ if( Connection->FuturePacketValidBytes[i / 8] == 0xFF ) {
+ i += 7; index += 7;
+ continue;
+ }
+ else if( !(Connection->FuturePacketValidBytes[i / 8] & (1 << (i%8))) )
+ break;
+
+ index ++;
+ if(index > TCP_WINDOW_SIZE)
+ index -= TCP_WINDOW_SIZE;
+ }
+ length = i;
+
+ index = Connection->NextSequenceRcv % TCP_WINDOW_SIZE;
+
+ // Write data to to the ring buffer
+ if( TCP_WINDOW_SIZE - index > length )
+ {
+ // Simple case
+ RingBuffer_Write( Connection->RecievedBuffer, Connection->FuturePacketData + index, length );
+ }
+ else
+ {
+ int endLen = TCP_WINDOW_SIZE - index;
+ // 2-part case
+ RingBuffer_Write( Connection->RecievedBuffer, Connection->FuturePacketData + index, endLen );
+ RingBuffer_Write( Connection->RecievedBuffer, Connection->FuturePacketData, endLen - length );
+ }
+
+ // Mark (now saved) bytes as invalid
+ // - Align index
+ while(index % 8 && length)
+ {
+ Connection->FuturePacketData[index] = 0;
+ Connection->FuturePacketData[index/8] &= ~(1 << (index%8));
+ index ++;
+ if(index > TCP_WINDOW_SIZE)
+ index -= TCP_WINDOW_SIZE;
+ length --;
+ }
+ while( length > 7 )
+ {
+ Connection->FuturePacketData[index] = 0;
+ Connection->FuturePacketValidBytes[index/8] = 0;
+ length -= 8;
+ index += 8;
+ if(index > TCP_WINDOW_SIZE)
+ index -= TCP_WINDOW_SIZE;
+ }
+ while(length)
+ {
+ Connection->FuturePacketData[index] = 0;
+ Connection->FuturePacketData[index/8] &= ~(1 << (index%8));
+ index ++;
+ if(index > TCP_WINDOW_SIZE)
+ index -= TCP_WINDOW_SIZE;
+ length --;
+ }
+
+ #else