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

Add in Driver Timeout Architecture #511

Open
LeStarch opened this issue May 4, 2021 · 2 comments
Open

Add in Driver Timeout Architecture #511

LeStarch opened this issue May 4, 2021 · 2 comments
Labels
enhancement Low Priority Low prioirty items given the current project priorities.

Comments

@LeStarch
Copy link
Collaborator

LeStarch commented May 4, 2021

F´ Version devel
Affected Component Drv

Feature Description

Currently there are no good ways to limit send and recv calls to a specific amount of time. This can be done, but should be done in a generic way that works for all driver types that implement the ByteStreamDriver interface.

Rationale

Calls to send and recvPoll should have a configurable timeout to prevent excessive time being spent in these calls.

@LeStarch
Copy link
Collaborator Author

LeStarch commented May 4, 2021

How To Accomplish this:

This can be accomplished fairly accurately using the select interface, a non-blocking file descriptor, and a timer object. If done with the same structuring as the IP interface, we could implement a timeout driver class that oversees sends and recvs.

Send Implementation Pseudocode (Assuming Non-Blocking Socket)

status send(int fd, char* bytes, int size, int timeout) {
    int rc = 0;
    int sent = 0;
    start = getTime(); // F´ time if possible
    while ((rc >= 0 and sent < size)  or ((rc == -1) and errnno == EINTER || ... EAGAIN || ... EWOULDBLOCK ) {
          remaining_timeout = getTime() - start;
          rc = select(..., fd, ..., remaining_timeout );
          if (errno == TIMEOUT) {
              return TIMEOUT;  
          }
          rc = send(fd, bytes + sent, size - sent)
          if (rc > 0) {
              sent += rc;
          }      
    }
    return (sent == size) ? SUCCESS : ERROR;
}

kubiak-jpl pushed a commit to abcouwer-jpl/fprime that referenced this issue Mar 2, 2022
ported static assert from lunarflashlight and neasc
@LeStarch LeStarch added the Low Priority Low prioirty items given the current project priorities. label Mar 23, 2022
@matt392code
Copy link
Contributor

Suggested Enhancements:
Driver Architecture:

class TimeoutByteStreamDriver : public ByteStreamDriver {
    private:
        ByteStreamDriver& wrapped_driver;
        const U32 send_timeout_ms;
        const U32 recv_timeout_ms;
        
    public:
        TimeoutByteStreamDriver(
            ByteStreamDriver& driver,
            U32 send_timeout,
            U32 recv_timeout
        );
        
        status_t send(const U8* const data, const U32 size) override;
        status_t recv(U8* const data, const U32 size) override;
};

Additional Features to Consider:

Configurable timeouts per operation
Timeout statistics tracking
Integration with F Prime's event system for timeout notifications
Mechanism to cancel pending operations

Testing Considerations:

Unit tests for various timeout scenarios
Tests for partial sends/receives
Edge case testing (0 timeout, very large timeout)
System tests for real-world timing behavior

Configuration:

struct TimeoutConfig {
    U32 send_timeout_ms;  // Send operation timeout
    U32 recv_timeout_ms;  // Receive operation timeout
    bool enable_stats;    // Enable timeout statistics
    U32 retry_count;      // Number of retries on timeout
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Low Priority Low prioirty items given the current project priorities.
Projects
None yet
Development

No branches or pull requests

2 participants