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.
Description
Compilation fails on macOS due to the
DGramSocketImpl
being an abstract class. The issue stems from the fact that the pure virtual functionclearRxCache
, declared in the base classDGramSocket
, is not implemented inDGramSocketImpl
for macOS. Interestingly, this method is implemented in the Linux and Windows versions (rplidar_sdk/sdk/src/arch/linux/net_socket.cpp
andrplidar_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 inDGramSocketImpl
for macOS. The following code snippet clears the receive cache usingselect
andrecv
system calls.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.