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

modified: Drv/TcpClient/TcpClientComponentImpl.cpp #2759

Merged
merged 6 commits into from
Jun 7, 2024

Conversation

menaman123
Copy link
Contributor

Related Issue(s) #2074
Has Unit Tests (y/n) no
Documentation Included (y/n) no

Change Description

Changed the getBuffer function to have a tunable size. There is a default size of 1024 so that it does not break any existing code.

Rationale

This removes the need of having to fork off of the fprime repo or autopatch everytime.

Testing/Review Recommendations

There is no unit tests to see if it'll break anything. Unsure where to begin to test to see.

Future Work

@LeStarch
Copy link
Collaborator

LeStarch commented Jun 7, 2024

@menaman123 sorry, I didn't catch your question. I do like that you have defaulted this, but I'd move the allocation size to the configure method. Store the values a a member (e.g. m_allocation_size) and then pass that member to the call.

Note: We should do separate PRs for TcpServer and UDP too (once this one is approved)!

@menaman123
Copy link
Contributor Author

@LeStarch Should i modify the getBuffer such that it returns the member allocate(0, m_allocation_size)?

@menaman123
Copy link
Contributor Author

@LeStarch I changed the header file, I was wondering should the default buffer size be hardcoded as 1024 or a variable called DEFAULT_BUFFER_SIZE should be created instead?

@LeStarch
Copy link
Collaborator

LeStarch commented Jun 7, 2024

One last change: use FwSizeType instead of size_t for these sizes. In F´ we use FwSizeType as the type of sizes.

I am ok with the hardcoded 1024. It is a default after all, and easily changed. Thanks for this change, we've needed it for some time!

@LeStarch
Copy link
Collaborator

LeStarch commented Jun 7, 2024

You missed the member variable change to FwSizeType too. I made that edit for you so you don't have to keep chasing nits.

Your code looks good. Normally, we'd prefix all member variables with this->m_allocation_type .... but this file does not do that anywhere and you were correct to maintain style within this file.

Once CI passes, we'll merge this!

@menaman123
Copy link
Contributor Author

Sweet thank you so much for the insight and teaching me the way!! @LeStarch

@LeStarch
Copy link
Collaborator

LeStarch commented Jun 7, 2024

The issue with CI is this: F´ is in the process of transitioning from fixed-width types (e.g. U32) to project configurable types (e.g. FwSizeType). In this case Fw::Buffer uses an older style (U32) and your changes now update to the new style.

Here is how to fix this. Add a cast to the allocation call to convert types:

    return allocate_out(0, static_cast<U32>(m_allocation_size));

Add this check to the configure method:

    FW_ASSERT(buffer_size <= std::numeric_limits<U32>::max(), buffer_size);

This check ensures that the configured buffer size fits within the limit of the old structure. We do this in configure so that the assert trips as early as possible.

You may need to include these headers (if not already done so):

#include <limits>
#include <Fw/Types/Assert.hpp>

@@ -126,6 +128,9 @@
Drv::SendStatus send_handler(const NATIVE_INT_TYPE portNum, Fw::Buffer& fwBuffer);

Drv::TcpClientSocket m_socket; //!< Socket implementation

// Member variable to store the buffer size
FwSizeType m_allocation_size;

Check notice

Code scanning / CodeQL

Use of basic integral type Note

m_allocation_size uses the basic integral type unsigned long rather than a typedef with size and signedness.
@@ -28,7 +29,12 @@
SocketIpStatus TcpClientComponentImpl::configure(const char* hostname,
const U16 port,
const U32 send_timeout_seconds,
const U32 send_timeout_microseconds) {
const U32 send_timeout_microseconds,
FwSizeType buffer_size) {

Check notice

Code scanning / CodeQL

Use of basic integral type Note

buffer_size uses the basic integral type unsigned long rather than a typedef with size and signedness.
@LeStarch LeStarch merged commit 7ff002c into nasa:devel Jun 7, 2024
34 checks passed
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.

2 participants