I'm writing a TCP implementation, using UDP sockets. My initial algorithm will be based off TCP Reno. My question is, since packets are byte-sized anyways, would there be any significant downsides to implementing the sliding window using maxNum Packets
rather than maxNum Bytes
? Isn't it pretty much the same thing?
For some code example, I currently do a mmap()
on my data, and then pack it into a map
:
int
ReliableSender::Packetize(char* data, int numBytes)
{
int seqNum = 1;
int offset = 0;
char* payload = NULL;
unsigned int length = sizeof(struct sockaddr_in);
bool dataRemaining = true;
while(dataRemaining)
{
size_t packetSize;
(numBytes > MTU) ? packetSize = MTU : packetSize = numBytes;
memcpy(payload, data, packetSize);
Packet pac = {seqNum, 0, payload};
dataMap.insert(make_pair(seqNum, pac));
if(numBytes > MTU)
payload = &data[offset];
else
dataRemaining = false;
offset += MTU;
numBytes -= MTU;
seqNum++;
}
return 0;
}
struct Packet
{
int seqNum;
int ackNum;
char* payload;
};
My thought was that I could simply adjust the sliding window by increasing the number of "packets" I send without an ACK
rather than a set number of bytes - is there anything wrong with this? This is for a very simple application; nothing that needs to be portable or placed into production anytime soon.