use select() instead of poll() as it's portable

This commit is contained in:
Andrzej Rybczak
2009-10-25 03:25:26 +01:00
parent 3e99bba5b8
commit e112e0d975
2 changed files with 17 additions and 8 deletions

View File

@@ -72,8 +72,7 @@ bool Connection::Connect()
return false; return false;
if (!itsPassword.empty()) if (!itsPassword.empty())
SendPassword(); SendPassword();
itsPoll.fd = mpd_connection_get_fd(itsConnection); itsFD = mpd_connection_get_fd(itsConnection);
itsPoll.events = POLLIN;
supportsIdle = Version() > 13; supportsIdle = Version() > 13;
// in UpdateStatus() we compare it to itsElapsedTimer[0], // in UpdateStatus() we compare it to itsElapsedTimer[0],
// and for the first time it has always evaluate to true // and for the first time it has always evaluate to true
@@ -169,8 +168,10 @@ void Connection::UpdateStatus()
if (isIdle) if (isIdle)
{ {
poll(&itsPoll, 1, 10); FD_ZERO(&itsPoll);
if (itsPoll.revents & POLLIN) FD_SET(itsFD, &itsPoll);
timeval timeout = { 0, 0 };
if (select(itsFD+1, &itsPoll, 0, 0, &timeout) == 1)
GoBusy(); GoBusy();
else else
{ {
@@ -220,8 +221,10 @@ void Connection::UpdateStatus()
// time equal to 0 even if song has changed, it sometimes // time equal to 0 even if song has changed, it sometimes
// returns the last second, so we need to bypass it by zeroing // returns the last second, so we need to bypass it by zeroing
// it in this case. // it in this case.
if (itsElapsed == mpd_status_get_total_time(itsCurrentStatus)) // NOTICE: it seems polling with select() instead of poll()
itsElapsed = 0; // fixes this, but that can just be more randomness.
//if (itsElapsed == mpd_status_get_total_time(itsCurrentStatus))
// itsElapsed = 0;
time(&itsElapsedTimer[0]); time(&itsElapsedTimer[0]);
} }
else else

View File

@@ -21,7 +21,12 @@
#ifndef _MPDPP_H #ifndef _MPDPP_H
#define _MPDPP_H #define _MPDPP_H
#include <poll.h> #ifdef WIN32
# include <winsock.h>
#else
# include <sys/select.h>
#endif
#include <vector> #include <vector>
#include <mpd/client.h> #include <mpd/client.h>
@@ -219,7 +224,8 @@ namespace MPD
int itsErrorCode; int itsErrorCode;
size_t itsMaxPlaylistLength; size_t itsMaxPlaylistLength;
pollfd itsPoll; fd_set itsPoll;
int itsFD;
bool isIdle; bool isIdle;
bool supportsIdle; bool supportsIdle;