0

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.

MrDuk
  • 16,578
  • 18
  • 74
  • 133

1 Answers1

1

Yes. TCP is a byte-stream protocol. You can send one byte at a times you can therefore change the receive window by one the at a time. You therefore can't express the receive window in packets.

If packets are byte-size you're just wasting bandwidth.

user207421
  • 305,947
  • 44
  • 307
  • 483