diff --git a/applications/gui2/src/main.cpp b/applications/gui2/src/main.cpp index bbdd04963627feac3b2cdc831e25ee5f15725df8..2367bd03f151f0b48a7c11b05675d154838972c6 100644 --- a/applications/gui2/src/main.cpp +++ b/applications/gui2/src/main.cpp @@ -92,6 +92,18 @@ FTLGui::FTLGui(int argc, char **argv) { if (io_->feed()->listSources().size() == 0) { adder->show(); } + + net_->onDisconnect([this](ftl::net::Peer *p) { + if (p->status() != ftl::net::Peer::kConnected) { + screen_->showError("Connection Failed", std::string("Could not connect to network peer: ") + p->getURI()); + } else { + screen_->showError("Disconnection", std::string("Network peer disconnected: ") + p->getURI()); + } + }); + + net_->onError([this](ftl::net::Peer *, const ftl::net::Error &err) { + + }); } FTLGui::~FTLGui() { diff --git a/components/net/cpp/include/ftl/net/peer.hpp b/components/net/cpp/include/ftl/net/peer.hpp index 91f3f2f06ebc5991e429ea743bb51ca0e5cc64b0..5ee90444c0e70a932039997eacc0b6e81d7523a9 100644 --- a/components/net/cpp/include/ftl/net/peer.hpp +++ b/components/net/cpp/include/ftl/net/peer.hpp @@ -101,6 +101,8 @@ class Peer { * Make a reconnect attempt. Called internally by Universe object. */ bool reconnect(); + + inline bool isOutgoing() const { return outgoing_; } /** * Test if the connection is valid. This returns true in all conditions @@ -263,6 +265,7 @@ class Peer { std::string uri_; // Original connection URI, or assumed URI ftl::UUID peerid_; // Received in handshake or allocated + bool outgoing_; ftl::net::Dispatcher *disp_; // For RPC call dispatch //std::vector<std::function<void(Peer &)>> open_handlers_; diff --git a/components/net/cpp/src/peer.cpp b/components/net/cpp/src/peer.cpp index ca2e13a0373068129aa45c7d8d891263b6d07e56..effe08b1ab062217b62892d520e45d52ad3d6018 100644 --- a/components/net/cpp/src/peer.cpp +++ b/components/net/cpp/src/peer.cpp @@ -187,6 +187,7 @@ Peer::Peer(SOCKET s, Universe *u, Dispatcher *d) : sock_(s), can_reconnect_(fals is_waiting_ = true; scheme_ = ftl::URI::SCHEME_TCP; + outgoing_ = false; int flags =1; if (setsockopt(s, IPPROTO_TCP, TCP_NODELAY, (const char *)&flags, sizeof(flags))) { LOG(ERROR) << "ERROR: setsocketopt(), TCP_NODELAY"; }; @@ -240,6 +241,7 @@ Peer::Peer(const char *pUri, Universe *u, Dispatcher *d) : can_reconnect_(true), status_ = kInvalid; sock_ = INVALID_SOCKET; + outgoing_ = true; disp_ = new Dispatcher(d); @@ -391,12 +393,12 @@ void Peer::_badClose(bool retry) { closesocket(sock_); #endif sock_ = INVALID_SOCKET; - status_ = kDisconnected; //auto i = find(sockets.begin(),sockets.end(),this); //sockets.erase(i); universe_->_notifyDisconnect(this); + status_ = kDisconnected; // Attempt auto reconnect? if (retry && can_reconnect_) {