-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Refactor Drv::Ip::UdpSocket to clean up state members and remove dependency on dynamic memory #3728
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
Merged
Merged
Changes from 10 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
42fbdec
Refactor UdpSocket to remove SocketState and the use of dynamic memor…
vincewoo 85b4568
Replacing some ASSERTs with proper SocketIpStatus. Adding some input …
vincewoo 5d00932
Refactoring UdpSocket to remove redundant m_recv_port and m_recv_host…
vincewoo 006f2f6
Fixing some documentation and renaming a variable to be more consistent
vincewoo 574dba4
Adding ADDRSTRLEN to spelling expect
vincewoo 484c5b9
Incorporating PR fixes and adding a new UT for zero length datagram
vincewoo 70be688
Replacing a strcpy with a Fw::StringUtils::string_copy
vincewoo 8987394
Removing incorrect UDP statuses in empty datagram test
vincewoo 401908a
Fixing bug in implementation of UdpSocket by overriding IpSocket impl…
vincewoo 2e68490
Merge branch 'devel' into FP-3716
vincewoo 319b38e
Incorporating PR fixes. Adding function argument checks for send/recv.
vincewoo 9ac24cd
Fixing build errors
vincewoo 5a2e11d
Incorporating PR comments
vincewoo 9a29699
Forgot to add change for IpSocket
vincewoo 7bc3ab2
Fixing asserts and removing virtual from recv that we shouldn't have …
vincewoo eb73a9d
Spelling
vincewoo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -161,40 +161,50 @@ | |
| } | ||
|
|
||
| SocketIpStatus IpSocket::recv(const SocketDescriptor& socketDescriptor, U8* data, U32& req_read) { | ||
| I32 size = 0; | ||
| // Try to read until we fail to receive data | ||
| for (U32 i = 0; (i < SOCKET_MAX_ITERATIONS) && (size <= 0); i++) { | ||
| errno = 0; | ||
| // Attempt to recv out data | ||
| size = this->recvProtocol(socketDescriptor, data, req_read); | ||
| I32 bytes_received_or_status; // Stores the return value from recvProtocol | ||
|
|
||
| // Nothing to be received | ||
| if ((size == -1) && ((errno == EAGAIN) || (errno == EWOULDBLOCK))) { | ||
| // Loop primarily for EINTR. Other conditions should lead to an earlier exit. | ||
| for (U32 i = 0; i < SOCKET_MAX_ITERATIONS; i++) { | ||
| errno = 0; | ||
| // Pass the current value of req_read (max buffer size) to recvProtocol. | ||
| // recvProtocol returns bytes read or -1 on error. | ||
| bytes_received_or_status = this->recvProtocol(socketDescriptor, data, req_read); | ||
|
||
|
|
||
| if (bytes_received_or_status > 0) { | ||
| // Successfully read data | ||
| req_read = static_cast<U32>(bytes_received_or_status); | ||
| return SOCK_SUCCESS; | ||
| } else if (bytes_received_or_status == 0) { | ||
| // For TCP (which IpSocket primarily serves as a base for, or when not overridden), | ||
| // a return of 0 from ::recv means the peer has performed an orderly shutdown. | ||
| req_read = 0; | ||
| return SOCK_NO_DATA_AVAILABLE; | ||
| } | ||
|
|
||
| // Error is EINTR, just try again | ||
| if ((size == -1) && (errno == EINTR)) { | ||
| continue; | ||
| } | ||
| // Zero bytes read reset or bad ef means we've disconnected | ||
| else if (size == 0 || ((size == -1) && ((errno == ECONNRESET) || (errno == EBADF)))) { | ||
| req_read = static_cast<U32>(size); | ||
| return SOCK_DISCONNECTED; | ||
| } | ||
| // Error returned, and it wasn't an interrupt, nor a disconnect | ||
| else if (size == -1) { | ||
| req_read = static_cast<U32>(size); | ||
| return SOCK_READ_ERROR; // Stop recv task on error | ||
| } else { // bytes_received_or_status == -1, an error occurred | ||
| if ((errno == EAGAIN) || (errno == EWOULDBLOCK)) { | ||
| // Non-blocking socket would block, or SO_RCVTIMEO timeout occurred. | ||
| req_read = 0; | ||
| return SOCK_NO_DATA_AVAILABLE; | ||
| } else if (errno == EINTR) { | ||
| // Interrupted system call. Retry if not the last iteration. | ||
| if (i == (SOCKET_MAX_ITERATIONS - 1)) { | ||
|
||
| req_read = 0; | ||
| return SOCK_INTERRUPTED_TRY_AGAIN; // Max retries for EINTR reached | ||
| } | ||
| // Loop will continue for EINTR. The 'continue' is implicit here. | ||
| } else if ((errno == ECONNRESET) || (errno == EBADF)) { | ||
| // Connection reset or bad file descriptor. | ||
| req_read = 0; | ||
| return SOCK_DISCONNECTED; // Or a more specific error like SOCK_READ_ERROR | ||
| } else { | ||
| // Other socket read error. | ||
| req_read = 0; | ||
| return SOCK_READ_ERROR; | ||
| } | ||
| } | ||
| } | ||
| req_read = static_cast<U32>(size); | ||
| // Prevent interrupted socket being viewed as success | ||
| if (size == -1) { | ||
| return SOCK_INTERRUPTED_TRY_AGAIN; | ||
| } | ||
| return SOCK_SUCCESS; | ||
| // If the loop completes, it means SOCKET_MAX_ITERATIONS of EINTR occurred. | ||
| req_read = 0; | ||
|
||
| return SOCK_INTERRUPTED_TRY_AGAIN; | ||
| } | ||
|
|
||
| } // namespace Drv | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check warning
Code scanning / CodeQL
Comparison result is always the same Warning