mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-22 01:11:42 +00:00
[wpinet] Add indication of success/failure to PortForwarder (#6697)
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
|
||||
#include <fmt/format.h>
|
||||
#include <wpi/DenseMap.h>
|
||||
#include <wpi/print.h>
|
||||
|
||||
#include "wpinet/EventLoopRunner.h"
|
||||
#include "wpinet/uv/GetAddrInfo.h"
|
||||
@@ -50,6 +51,7 @@ void PortForwarder::Add(unsigned int port, std::string_view remoteHost,
|
||||
m_impl->runner.ExecSync([&](uv::Loop& loop) {
|
||||
auto server = uv::Tcp::Create(loop);
|
||||
if (!server) {
|
||||
wpi::print(stderr, "PortForwarder: Creating server failed\n");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -62,6 +64,7 @@ void PortForwarder::Add(unsigned int port, std::string_view remoteHost,
|
||||
auto& loop = serverPtr->GetLoopRef();
|
||||
auto client = serverPtr->Accept();
|
||||
if (!client) {
|
||||
wpi::print(stderr, "PortForwarder: Connecting to client failed\n");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -75,6 +78,7 @@ void PortForwarder::Add(unsigned int port, std::string_view remoteHost,
|
||||
|
||||
auto remote = uv::Tcp::Create(loop);
|
||||
if (!remote) {
|
||||
wpi::print(stderr, "PortForwarder: Creating remote failed\n");
|
||||
client->Close();
|
||||
return;
|
||||
}
|
||||
@@ -106,6 +110,7 @@ void PortForwarder::Add(unsigned int port, std::string_view remoteHost,
|
||||
return;
|
||||
}
|
||||
*(client->GetData<bool>()) = true;
|
||||
wpi::print("PortForwarder: Connected to remote port\n");
|
||||
|
||||
// close both when either side closes
|
||||
client->end.connect([clientPtr = client.get(), remoteWeak] {
|
||||
|
||||
Reference in New Issue
Block a user