MacOS: fix(network): fixes ArticBase UDP buffer handling on macOS (#1263)

* MacOS: fix(network): fixes ArticBase UDP buffer handling on macOS

- Set minimum 8KB UDP receive buffer size on macOS for reliable operation
- Add platform-specific buffer size handling with conditional compilation
- Enhance error logging with errno details and buffer size verification
- Maintain backward compatibility with existing buffer sizes on other platforms

Fixes ArticBase controller input reliability issues on macOS by ensuring
adequate UDP buffer capacity for real-time controller data transmission.

* Remove redundant log

---------

Co-authored-by: Alex Molina <alexmolina@MacBook-Air-de-Alex.local>
Co-authored-by: PabloMK7 <hackyglitch2@gmail.com>
This commit is contained in:
Alex 2025-08-07 21:16:15 +02:00 committed by GitHub
parent 1e9614fe4f
commit e5838edf9f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -6,6 +6,7 @@
#include "common/assert.h" #include "common/assert.h"
#include "common/logging/log.h" #include "common/logging/log.h"
#include "algorithm"
#include "chrono" #include "chrono"
#include "limits.h" #include "limits.h"
#include "memory" #include "memory"
@ -143,15 +144,35 @@ void Client::UDPStream::Handle() {
} }
// Limit receive buffer so that packets don't get qeued and are dropped instead. // Limit receive buffer so that packets don't get qeued and are dropped instead.
int buffer_size_int = static_cast<int>(buffer_size); // macOS requires larger UDP buffer sizes for reliable operation
if (::setsockopt(main_socket, SOL_SOCKET, SO_RCVBUF, reinterpret_cast<char*>(&buffer_size_int), #ifdef __APPLE__
sizeof(buffer_size_int)) || const int min_macos_buffer_size = 8192; // 8KB minimum for macOS
int effective_buffer_size = std::max(static_cast<int>(buffer_size), min_macos_buffer_size);
#else
int effective_buffer_size = static_cast<int>(buffer_size);
#endif
if (::setsockopt(main_socket, SOL_SOCKET, SO_RCVBUF,
reinterpret_cast<char*>(&effective_buffer_size),
sizeof(effective_buffer_size)) < 0 ||
!thread_run) { !thread_run) {
LOG_ERROR(Network, "Cannot change receive buffer size: {} (errno: {})", strerror(GET_ERRNO),
GET_ERRNO);
closesocket(main_socket); closesocket(main_socket);
LOG_ERROR(Network, "Cannot change receive buffer size");
return; return;
} }
// Verify the buffer size was actually set
socklen_t actual_size_len = sizeof(int);
int actual_buffer_size;
if (::getsockopt(main_socket, SOL_SOCKET, SO_RCVBUF,
reinterpret_cast<char*>(&actual_buffer_size), &actual_size_len) == 0) {
LOG_INFO(Network, "UDP buffer size set to: {} (requested: {})", actual_buffer_size,
effective_buffer_size);
} else {
LOG_WARNING(Network, "Could not verify UDP buffer size setting");
}
// Send data to server so that it knows client address. // Send data to server so that it knows client address.
char zero = '\0'; char zero = '\0';
int send_res = int send_res =