mirror of
https://github.com/PhotonVision/photonvision
synced 2026-06-26 01:51:40 +00:00
[TSP] Move Bind() to Start (#1538)
Fixes UB with static init. Turns out starting threads in static init doesn't work on windows.
This commit is contained in:
@@ -156,17 +156,11 @@ wpi::tsp::TimeSyncClient::TimeSyncClient(std::string_view server,
|
||||
std::function<uint64_t()> timeProvider)
|
||||
: m_logger(::ClientLoggerFunc),
|
||||
m_timeProvider(timeProvider),
|
||||
m_udp{wpi::uv::Udp::Create(m_loopRunner.GetLoop(), AF_INET)},
|
||||
m_pingTimer{wpi::uv::Timer::Create(m_loopRunner.GetLoop())},
|
||||
m_udp{},
|
||||
m_pingTimer{},
|
||||
m_serverIP{server},
|
||||
m_serverPort{remote_port},
|
||||
m_loopDelay(ping_delay) {
|
||||
struct sockaddr_in serverAddr;
|
||||
uv::NameToAddr(m_serverIP, m_serverPort, &serverAddr);
|
||||
|
||||
m_loopRunner.ExecSync(
|
||||
[this, serverAddr](uv::Loop&) { m_udp->Connect(serverAddr); });
|
||||
|
||||
// fmt::println("Starting client (with server address {}:{})", server,
|
||||
// remote_port);
|
||||
}
|
||||
@@ -175,6 +169,13 @@ void wpi::tsp::TimeSyncClient::Start() {
|
||||
// fmt::println("Connecting received");
|
||||
|
||||
m_loopRunner.ExecSync([this](uv::Loop&) {
|
||||
struct sockaddr_in serverAddr;
|
||||
uv::NameToAddr(m_serverIP, m_serverPort, &serverAddr);
|
||||
|
||||
m_udp = {wpi::uv::Udp::Create(m_loopRunner.GetLoop(), AF_INET)};
|
||||
m_pingTimer = {wpi::uv::Timer::Create(m_loopRunner.GetLoop())};
|
||||
|
||||
m_udp->Connect(serverAddr);
|
||||
m_udp->received.connect(&wpi::tsp::TimeSyncClient::UdpCallback, this);
|
||||
m_udp->StartRecv();
|
||||
});
|
||||
|
||||
@@ -101,13 +101,13 @@ wpi::tsp::TimeSyncServer::TimeSyncServer(int port,
|
||||
std::function<uint64_t()> timeProvider)
|
||||
: m_logger{::ServerLoggerFunc},
|
||||
m_timeProvider{timeProvider},
|
||||
m_udp{wpi::uv::Udp::Create(m_loopRunner.GetLoop(), AF_INET)} {
|
||||
m_loopRunner.ExecSync(
|
||||
[this, port](uv::Loop&) { m_udp->Bind("0.0.0.0", port); });
|
||||
}
|
||||
m_udp{},
|
||||
m_port(port) {}
|
||||
|
||||
void wpi::tsp::TimeSyncServer::Start() {
|
||||
m_loopRunner.ExecSync([this](uv::Loop&) {
|
||||
m_udp = {wpi::uv::Udp::Create(m_loopRunner.GetLoop(), AF_INET)};
|
||||
m_udp->Bind("0.0.0.0", m_port);
|
||||
m_udp->received.connect(&wpi::tsp::TimeSyncServer::UdpCallback, this);
|
||||
m_udp->StartRecv();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user