Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor CS move functions to chunkserver entry #210

Draft
wants to merge 8 commits into
base: dev
Choose a base branch
from

Conversation

lgsilva3087
Copy link
Contributor

[MUST be merged after PR#206]

This commit moves most of the hanging functions in
network_worker_thread.cc to the ChunkserverEntry class. Where they make
more sense due to their responsibilities. Also:

  • The code now is shorter and easier to read.
  • There is no need to pass a pointer to the ChunkserverEntry every time
    for almost all functions.
  • Lines are also shorter.
  • Every function was documented.
  • Small code style aplied close to the related lines.
  • Better function names.

This is a partial refactor, the next step is to separate the
ChunkserverEntry into its own files.

ChunkserverEntry was using a C-like linked list like this:
- PacketStruct *outputHead = nullptr;
- PacketStruct **outputTail = &outputHead;
This change replaces it with a std::list:
- std::list<std::unique_ptr<PacketStruct>> outputPackets;

The commit also uses smart pointers for the list elements and for
the members readPacket and writePacket.

Some of the related functions were moved (and renamed) to the
ChunkserverEntry struct, where they look more natural.
This commit is focused on replacing the old 'uint8_t *packet' by
'std::vector<uint8_t> packet' in PacketStruct. The change looks simple
at first glance but aims for:
- Simplified memory management (malloc and free was used before).
- Reuse of already allocated memory.
- Use of move semantics.
- Simplified destruction and cleanup.
- Shorter code.
- Remove void* and casts.
- Rename variable 'i' to bytesRead or bytesWritten according context.
- Replace NULL by nullptr.
- Remove magic number.
Better usage of emplace_back in NetworkWorkerThread to avoid temporary
empty object creation.
The destructor handles this automatically.
Even if the probability is very low, calling front in an empty list
could trigger undefined behavior.
This commit moves most of the hanging functions in
network_worker_thread.cc to the ChunkserverEntry class. Where they make
more sense due to their responsibilities. Also:
- The code now is shorter and easier to read.
- There is no need to pass a pointer to the ChunkserverEntry every time
  for almost all functions.
- Lines are also shorter.
- Every function was documented.
- Small code style aplied close to the related lines.
- Better function names.

This is a partial refactor, the next step is to separate the
ChunkserverEntry into its own files.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant