some improvements for handling mpd connection

This commit is contained in:
Andrzej Rybczak
2008-12-21 18:59:00 +01:00
parent 094c4e3ab3
commit 497f2dd4ff
2 changed files with 10 additions and 4 deletions

View File

@@ -132,11 +132,17 @@ void Connection::SetErrorHandler(ErrorHandler handler, void *data)
void Connection::UpdateStatus() void Connection::UpdateStatus()
{ {
if (!itsConnection)
return;
CheckForErrors(); CheckForErrors();
if (itsOldStatus) if (itsOldStatus)
mpd_freeStatus(itsOldStatus); mpd_freeStatus(itsOldStatus);
itsOldStatus = itsCurrentStatus; itsOldStatus = itsCurrentStatus;
itsCurrentStatus = 0;
mpd_sendStatusCommand(itsConnection); mpd_sendStatusCommand(itsConnection);
itsCurrentStatus = mpd_getStatus(itsConnection); itsCurrentStatus = mpd_getStatus(itsConnection);
@@ -849,6 +855,7 @@ int Connection::CheckForErrors()
itsErrorCode = 0; itsErrorCode = 0;
if (itsConnection->error) if (itsConnection->error)
{ {
itsErrorMessage = itsConnection->errorStr;
if (itsConnection->error == MPD_ERROR_ACK) if (itsConnection->error == MPD_ERROR_ACK)
{ {
// this is to avoid setting too small max size as we check it before fetching current status // this is to avoid setting too small max size as we check it before fetching current status
@@ -862,13 +869,13 @@ int Connection::CheckForErrors()
} }
else else
{ {
isConnected = 0; // the rest of errors are fatal to connection
if (itsErrorHandler) if (itsErrorHandler)
itsErrorHandler(this, itsConnection->error, itsConnection->errorStr, itsErrorHandlerUserdata); itsErrorHandler(this, itsConnection->error, itsConnection->errorStr, itsErrorHandlerUserdata);
itsErrorCode = itsConnection->error; itsErrorCode = itsConnection->error;
Disconnect(); // the rest of errors are fatal to connection
} }
itsErrorMessage = itsConnection->errorStr; if (itsConnection)
mpd_clearError(itsConnection); mpd_clearError(itsConnection);
} }
return itsErrorCode; return itsErrorCode;
} }

View File

@@ -363,7 +363,6 @@ int main(int argc, char *argv[])
if (!Mpd->Connected()) if (!Mpd->Connected())
{ {
ShowMessage("Attempting to reconnect..."); ShowMessage("Attempting to reconnect...");
Mpd->Disconnect();
if (Mpd->Connect()) if (Mpd->Connect())
ShowMessage("Connected!"); ShowMessage("Connected!");
messages_allowed = 0; messages_allowed = 0;