summaryrefslogtreecommitdiff
path: root/p2pvr/lib/tuner.cpp
diff options
context:
space:
mode:
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++;
}
}
}