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

Missing clearRxCache Implementation in DGramSocketImpl for macOS Causes Compilation Error #122

Open
Eotel opened this issue Sep 22, 2023 · 1 comment

Comments

@Eotel
Copy link

Eotel commented Sep 22, 2023

Description

Compilation fails on macOS due to the DGramSocketImpl being an abstract class. The issue stems from the fact that the pure virtual function clearRxCache, declared in the base class DGramSocket, is not implemented in DGramSocketImpl for macOS. Interestingly, this method is implemented in the Linux and Windows versions (rplidar_sdk/sdk/src/arch/linux/net_socket.cpp and rplidar_sdk/sdk/src/arch/win32/net_socket.cpp), but is missing from the macOS version (rplidar_sdk/sdk/src/arch/macOS/net_socket.cpp).

Solution

Implement the clearRxCache method in DGramSocketImpl for macOS. The following code snippet clears the receive cache using select and recv system calls.

virtual u_result clearRxCache()
{
    timeval tv;
    tv.tv_sec = 0;
    tv.tv_usec = 0;
    fd_set rdset;
    FD_ZERO(&rdset);
    FD_SET(_socket_fd, &rdset);

    int res = -1;
    char recv_data[2];
    memset(recv_data, 0, sizeof(recv_data));
    while (true) {
        res = select(FD_SETSIZE, &rdset, nullptr, nullptr, &tv);
        if (res == 0) break;
        recv(_socket_fd, recv_data, 1, 0);
    }
    return RESULT_OK;
}

With this implementation, the class is no longer abstract, and the code successfully compiles on macOS.

Additional Notes

If the method was deliberately not implemented for macOS, insights into the reasoning would be appreciated. This will help the community understand any platform-specific constraints or decisions.

@JetForMe
Copy link

I just ran into this too. Thanks for the fix!

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

No branches or pull requests

2 participants