Skip to content

Commit

Permalink
AP_Networking: allow reconnection to TCP server or client
Browse files Browse the repository at this point in the history
  • Loading branch information
bugobliterator authored and tridge committed Jul 17, 2024
1 parent 5f9abc0 commit 5a54d9a
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions libraries/AP_Networking/AP_Networking_port.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <AP_Math/AP_Math.h>
#include <AP_SerialManager/AP_SerialManager.h>
#include <AP_HAL/utility/packetise.h>
#include <errno.h>

extern const AP_HAL::HAL& hal;

Expand Down Expand Up @@ -413,6 +414,14 @@ bool AP_Networking::Port::send_receive(void)
WITH_SEMAPHORE(sem);
writebuffer->advance(ret);
active = true;
} else if (errno == ENOTCONN &&
(type == NetworkPortType::TCP_CLIENT || type == NetworkPortType::TCP_SERVER)) {
// close socket and mark as disconnected, so we can reconnect with another client or when server comes back
GCS_SEND_TEXT(MAV_SEVERITY_INFO, "TCP[%u]: disconnected", unsigned(state.idx));
sock->close();
delete sock;
sock = nullptr;
connected = false;
}
}

Expand Down

0 comments on commit 5a54d9a

Please sign in to comment.