summaryrefslogtreecommitdiff
path: root/src/mpdpp.cpp
diff options
context:
space:
mode:
authorAndrzej Rybczak <electricityispower@gmail.com>2009-10-25 20:44:07 +0100
committerAndrzej Rybczak <electricityispower@gmail.com>2009-10-25 20:44:07 +0100
commitdd04406ee551e9c7557c7791d0d59a9cc0ffd434 (patch)
treebe4e99e2e7e40846680b5099a90f5ed0885d67df /src/mpdpp.cpp
parent08f4459b5461ecefad4a26910a1dd155c32181ca (diff)
poll both stdin and mpd using one select()
this allows for immediate reading mpd events
Diffstat (limited to 'src/mpdpp.cpp')
-rw-r--r--src/mpdpp.cpp30
1 files changed, 14 insertions, 16 deletions
diff --git a/src/mpdpp.cpp b/src/mpdpp.cpp
index fe091d5b..7ed7818a 100644
--- a/src/mpdpp.cpp
+++ b/src/mpdpp.cpp
@@ -151,14 +151,14 @@ void Connection::GoIdle()
isIdle = 1;
}
-mpd_idle Connection::GoBusy()
+int Connection::GoBusy()
{
if (isIdle && mpd_send_noidle(itsConnection))
{
isIdle = 0;
return mpd_recv_idle(itsConnection, 1);
}
- return mpd_idle(0);
+ return 0;
}
void Connection::UpdateStatus()
@@ -166,13 +166,14 @@ void Connection::UpdateStatus()
if (!itsConnection)
return;
+ int idle_mask = 0;
if (isIdle)
{
- FD_ZERO(&itsPoll);
- FD_SET(itsFD, &itsPoll);
- timeval timeout = { 0, 0 };
- if (select(itsFD+1, &itsPoll, 0, 0, &timeout) == 1)
- GoBusy();
+ if (hasData)
+ {
+ idle_mask = GoBusy();
+ hasData = 0;
+ }
else
{
// count local elapsed time as we don't receive
@@ -217,14 +218,6 @@ void Connection::UpdateStatus()
{
// sync local elapsed time counter with mpd
itsElapsed = mpd_status_get_elapsed_time(itsCurrentStatus);
- // little hack as it seems mpd doesn't always return elapsed
- // time equal to 0 even if song has changed, it sometimes
- // returns the last second, so we need to bypass it by zeroing
- // it in this case.
- // NOTICE: it seems polling with select() instead of poll()
- // fixes this, but that can just be more randomness.
- //if (itsElapsed == mpd_status_get_total_time(itsCurrentStatus))
- // itsElapsed = 0;
time(&itsElapsedTimer[0]);
}
else
@@ -274,7 +267,12 @@ void Connection::UpdateStatus()
itsChanges.StatusFlags = itsChanges.Repeat || itsChanges.Random || itsChanges.Single || itsChanges.Consume || itsChanges.Crossfade || itsChanges.DBUpdating;
}
itsUpdater(this, itsChanges, itsErrorHandlerUserdata);
- GoIdle();
+ // below conditionals are a hack to workaround mpd bug 2608/2612
+ // by fetching another status with correct values after a while
+ if (!((idle_mask & MPD_IDLE_PLAYER) && !itsChanges.PlayerState))
+ GoIdle();
+ else if (supportsIdle && !isIdle)
+ OrderDataFetching();
}
}