mercredi 8 avril 2020

Packet generator in C++ with memory and latency constraints

I have to send data over a network (for some definition of network) stream, consisting of:

  1. A preamble;
  2. a payload; and
  3. a checksum.

I have two constraints: little memory available and need to keep latency low, so buffering the packet or payload is out of the question.

Given a free choice of implementation language I would have used something with co-routine support and write a pair of functions, let's call them transmitPacket() and generatePayload(), of which the former:

  1. Sends the preamble;
  2. reads the payload one byte at a time from generatePayload();
  3. sends the payload byte;
  4. updates the checksum;
  5. when the payload is done, sends the checksum.

This would have been trivial and expressed the intent clearly to future maintainers.

Sadly, I don't have a free choice of language. I am stuck with C++11.

I cannot think of a clear and clean way of approaching this problem given the aforementioned constraints, so if you have experience with similar problems in the past, any implementation suggestions would be welcome.

Aucun commentaire:

Enregistrer un commentaire