summaryrefslogtreecommitdiff
path: root/p2pvr/lib/tuner.cpp
diff options
context:
space:
mode:
authorrandomdan <randomdan@localhost>2014-01-31 21:01:56 +0000
committerrandomdan <randomdan@localhost>2014-01-31 21:01:56 +0000
commitd649bd72d98de0e834f1debfae38dfd98049aaa7 (patch)
treea82008b333c81e4a91a11710c2c29da41c11f247 /p2pvr/lib/tuner.cpp
parentRefactor tuner to use specific implementations of new interface for send diff... (diff)
downloadp2pvr-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.cpp32
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++;
}
}
}