diff --git a/deploy/hyperion.tar.gz.REMOVED.git-id b/deploy/hyperion.tar.gz.REMOVED.git-id index d99fb231..fad44076 100644 --- a/deploy/hyperion.tar.gz.REMOVED.git-id +++ b/deploy/hyperion.tar.gz.REMOVED.git-id @@ -1 +1 @@ -a975349d4d5b010597f15b5efa6363f43434627f \ No newline at end of file +27dcc318ae9a9226676fb33626500e57703d7b6d \ No newline at end of file diff --git a/include/xbmcvideochecker/XBMCVideoChecker.h b/include/xbmcvideochecker/XBMCVideoChecker.h index 97e1bf1a..08fc4236 100644 --- a/include/xbmcvideochecker/XBMCVideoChecker.h +++ b/include/xbmcvideochecker/XBMCVideoChecker.h @@ -65,6 +65,9 @@ private slots: /// Called when disconnected from XBMC void disconnected(); + /// reconnect to XBMC + void reconnect(); + /// Called when a connection error was encountered void connectionError(QAbstractSocket::SocketError error); diff --git a/libsrc/xbmcvideochecker/XBMCVideoChecker.cpp b/libsrc/xbmcvideochecker/XBMCVideoChecker.cpp index af755f52..0c396693 100644 --- a/libsrc/xbmcvideochecker/XBMCVideoChecker.cpp +++ b/libsrc/xbmcvideochecker/XBMCVideoChecker.cpp @@ -44,7 +44,7 @@ XBMCVideoChecker::XBMCVideoChecker(const std::string & address, uint16_t port, b void XBMCVideoChecker::start() { - disconnected(); + reconnect(); } void XBMCVideoChecker::receiveReply() @@ -157,17 +157,42 @@ void XBMCVideoChecker::connected() void XBMCVideoChecker::disconnected() { std::cout << "XBMC Disconnected" << std::endl; - - // try to connect - _socket.connectToHost(_address, _port); + reconnect(); } -void XBMCVideoChecker::connectionError(QAbstractSocket::SocketError) +void XBMCVideoChecker::reconnect() { - std::cout << "XBMC Connection error" << std::endl; + if (_socket.state() == QTcpSocket::ConnectedState) + { + return; + } - // try to connect again in 1 second - QTimer::singleShot(1000, this, SLOT(disconnected())); + // try to connect + switch (_socket.state()) + { + case QTcpSocket::ConnectingState: + // Somehow when XBMC restarts we get stuck in connecting state + // If we get here we tried to connect already for 5 seconds. abort and try again in 1 second. + _socket.reset(); + _socket.waitForDisconnected(50); + QTimer::singleShot(1000, this, SLOT(reconnect())); + break; + case QTcpSocket::UnconnectedState: + _socket.connectToHost(_address, _port); + QTimer::singleShot(10000, this, SLOT(reconnect())); + break; + default: + QTimer::singleShot(10000, this, SLOT(reconnect())); + break; + } +} + +void XBMCVideoChecker::connectionError(QAbstractSocket::SocketError error) +{ + std::cout << "XBMC Connection error (" << error << ")" << std::endl; + + // close the socket + _socket.close(); } void XBMCVideoChecker::setGrabbingMode(GrabbingMode newGrabbingMode)