Skip to content
Snippets Groups Projects
Commit 00fcc9dd authored by Nicolas Pope's avatar Nicolas Pope
Browse files

Display connection error dialogs

parent 12a0bac8
No related branches found
No related tags found
1 merge request!316Resolves #343 GUI and Frame Refactor
...@@ -92,6 +92,18 @@ FTLGui::FTLGui(int argc, char **argv) { ...@@ -92,6 +92,18 @@ FTLGui::FTLGui(int argc, char **argv) {
if (io_->feed()->listSources().size() == 0) { if (io_->feed()->listSources().size() == 0) {
adder->show(); 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() { FTLGui::~FTLGui() {
......
...@@ -101,6 +101,8 @@ class Peer { ...@@ -101,6 +101,8 @@ class Peer {
* Make a reconnect attempt. Called internally by Universe object. * Make a reconnect attempt. Called internally by Universe object.
*/ */
bool reconnect(); bool reconnect();
inline bool isOutgoing() const { return outgoing_; }
/** /**
* Test if the connection is valid. This returns true in all conditions * Test if the connection is valid. This returns true in all conditions
...@@ -263,6 +265,7 @@ class Peer { ...@@ -263,6 +265,7 @@ class Peer {
std::string uri_; // Original connection URI, or assumed URI std::string uri_; // Original connection URI, or assumed URI
ftl::UUID peerid_; // Received in handshake or allocated ftl::UUID peerid_; // Received in handshake or allocated
bool outgoing_;
ftl::net::Dispatcher *disp_; // For RPC call dispatch ftl::net::Dispatcher *disp_; // For RPC call dispatch
//std::vector<std::function<void(Peer &)>> open_handlers_; //std::vector<std::function<void(Peer &)>> open_handlers_;
......
...@@ -187,6 +187,7 @@ Peer::Peer(SOCKET s, Universe *u, Dispatcher *d) : sock_(s), can_reconnect_(fals ...@@ -187,6 +187,7 @@ Peer::Peer(SOCKET s, Universe *u, Dispatcher *d) : sock_(s), can_reconnect_(fals
is_waiting_ = true; is_waiting_ = true;
scheme_ = ftl::URI::SCHEME_TCP; scheme_ = ftl::URI::SCHEME_TCP;
outgoing_ = false;
int flags =1; int flags =1;
if (setsockopt(s, IPPROTO_TCP, TCP_NODELAY, (const char *)&flags, sizeof(flags))) { LOG(ERROR) << "ERROR: setsocketopt(), TCP_NODELAY"; }; 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), ...@@ -240,6 +241,7 @@ Peer::Peer(const char *pUri, Universe *u, Dispatcher *d) : can_reconnect_(true),
status_ = kInvalid; status_ = kInvalid;
sock_ = INVALID_SOCKET; sock_ = INVALID_SOCKET;
outgoing_ = true;
disp_ = new Dispatcher(d); disp_ = new Dispatcher(d);
...@@ -391,12 +393,12 @@ void Peer::_badClose(bool retry) { ...@@ -391,12 +393,12 @@ void Peer::_badClose(bool retry) {
closesocket(sock_); closesocket(sock_);
#endif #endif
sock_ = INVALID_SOCKET; sock_ = INVALID_SOCKET;
status_ = kDisconnected;
//auto i = find(sockets.begin(),sockets.end(),this); //auto i = find(sockets.begin(),sockets.end(),this);
//sockets.erase(i); //sockets.erase(i);
universe_->_notifyDisconnect(this); universe_->_notifyDisconnect(this);
status_ = kDisconnected;
// Attempt auto reconnect? // Attempt auto reconnect?
if (retry && can_reconnect_) { if (retry && can_reconnect_) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment