diff options
author | randomdan <randomdan@localhost> | 2014-01-31 21:01:56 +0000 |
---|---|---|
committer | randomdan <randomdan@localhost> | 2014-01-31 21:01:56 +0000 |
commit | d649bd72d98de0e834f1debfae38dfd98049aaa7 (patch) | |
tree | a82008b333c81e4a91a11710c2c29da41c11f247 /p2pvr/lib/tuner.cpp | |
parent | Refactor tuner to use specific implementations of new interface for send diff... (diff) | |
download | p2pvr-d649bd72d98de0e834f1debfae38dfd98049aaa7.tar.bz2 p2pvr-d649bd72d98de0e834f1debfae38dfd98049aaa7.tar.xz p2pvr-d649bd72d98de0e834f1debfae38dfd98049aaa7.zip |
Fixes around the new muxer and sender features
Diffstat (limited to 'p2pvr/lib/tuner.cpp')
-rw-r--r-- | p2pvr/lib/tuner.cpp | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/p2pvr/lib/tuner.cpp b/p2pvr/lib/tuner.cpp index 8ebf1a2..fe90231 100644 --- a/p2pvr/lib/tuner.cpp +++ b/p2pvr/lib/tuner.cpp @@ -48,9 +48,12 @@ Tuner::Tuner(const boost::filesystem::path & df) : Tuner::~Tuner() { - while (!backgroundClients.empty()) { - close(backgroundClients.begin()->first); - backgroundClients.erase(backgroundClients.begin()); + { + std::lock_guard<std::mutex> g(lock); + while (!backgroundClients.empty()) { + close(backgroundClients.begin()->first); + backgroundClients.erase(backgroundClients.begin()); + } } if (backgroundThread) { backgroundThread->join(); @@ -334,20 +337,25 @@ Tuner::senderThread() default: { // stuff to do std::lock_guard<std::mutex> g(lock); - BOOST_FOREACH(const auto & c, backgroundClients) { - if (FD_ISSET(c.first, &rfds)) { + for (auto c = backgroundClients.begin(); c != backgroundClients.end(); ) { + if (FD_ISSET(c->first, &rfds)) { // Read it P2PVR::Data buf(1 << 16); - int nr = read(c.first, &buf.front(), buf.size()); + int nr = read(c->first, &buf.front(), buf.size()); if (nr < 0) { Logger()->messagebf(LOG_DEBUG, "%s: read failed (%d:%s)", __PRETTY_FUNCTION__, errno, strerror(errno)); - close(c.first); - backgroundClients.erase(c.first); - break; // backgroundClients has changed, bailout and start again + close(c->first); + c = backgroundClients.erase(c); } - size_t n = nr; - buf.resize(n); - c.second->NewData(buf); + else { + size_t n = nr; + buf.resize(n); + c->second->NewData(buf); + c++; + } + } + else { + c++; } } } |