Skip to content

Commit

Permalink
ExternalStreamHandler: Under stress, the external application may not
Browse files Browse the repository at this point in the history
respond as quick as we would like.  Give it a few tries before aborting.
  • Loading branch information
jpoet committed Feb 2, 2017
1 parent 3d20c84 commit 2a66730
Showing 1 changed file with 62 additions and 59 deletions.
121 changes: 62 additions & 59 deletions mythtv/libs/libmythtv/recorders/ExternalStreamHandler.cpp
Expand Up @@ -866,29 +866,15 @@ bool ExternalStreamHandler::RestartStream(void)


if (streaming) if (streaming)
{ {
for (idx = 0; idx < 5; ++idx) if (!StopStreaming())
{ return false;
ClearError();
m_IO->ClearError();
if (StopStreaming())
break;
usleep(100000);
}
} }


usleep(500000); usleep(500000);


if (streaming) if (streaming)
{ {
for (idx = 0; idx < 5; ++idx) return StartStreaming(false);
{
ClearError();
m_IO->ClearError();
if (StartStreaming(false))
return true;
usleep(100000);
}
return false;
} }


return true; return true;
Expand Down Expand Up @@ -1027,61 +1013,78 @@ bool ExternalStreamHandler::StopStreaming(void)
bool ExternalStreamHandler::ProcessCommand(const QString & cmd, uint timeout, bool ExternalStreamHandler::ProcessCommand(const QString & cmd, uint timeout,
QString & result) QString & result)
{ {
bool okay;

LOG(VB_RECORD, LOG_DEBUG, LOC + QString("ProcessCommand('%1')") LOG(VB_RECORD, LOG_DEBUG, LOC + QString("ProcessCommand('%1')")
.arg(cmd)); .arg(cmd));


QMutexLocker locker(&m_IO_lock); for (int idx = 0; idx < 10; ++idx)

if (!m_IO)
{ {
m_error = "External I/O not ready!"; QMutexLocker locker(&m_IO_lock);
LOG(VB_RECORD, LOG_ERR, LOC + m_error);
return false;
}


QByteArray buf(cmd.toUtf8(), cmd.size()); if (!m_IO)
buf += '\n'; {
m_error = "External I/O not ready!";
LOG(VB_RECORD, LOG_ERR, LOC + m_error);
return false;
}


if (m_IO->Error()) QByteArray buf(cmd.toUtf8(), cmd.size());
{ buf += '\n';
LOG(VB_GENERAL, LOG_ERR, "External Recorder in bad state: " +
m_IO->ErrorString());
return false;
}


/* Try to keep in sync, if External app was too slow in responding if (m_IO->Error())
* to previous query, consume the response before sending new query */ {
m_IO->GetStatus(0); LOG(VB_GENERAL, LOG_ERR, "External Recorder in bad state: " +
m_IO->ErrorString());
return false;
}


/* Send new query */ /* Try to keep in sync, if External app was too slow in responding
m_IO->Write(buf); * to previous query, consume the response before sending new query */
result = m_IO->GetStatus(timeout); m_IO->GetStatus(0);
if (m_IO->Error())
{ /* Send new query */
m_error = m_IO->ErrorString(); m_IO->Write(buf);
_error = true; result = m_IO->GetStatus(timeout);
LOG(VB_GENERAL, LOG_ERR, "Failed to read from External Recorder: " + if (m_IO->Error())
m_error); {
return false; m_error = m_IO->ErrorString();
} _error = true;
LOG(VB_GENERAL, LOG_ERR, "Failed to read from External Recorder: " +
m_error);
return false;
}

if (result.size() < 1)
LOG(VB_GENERAL, LOG_WARNING, LOC +
QString("External Recorder did not respond to '%1'").arg(cmd));
else
{
okay = result.startsWith("OK");
if (okay || result.startsWith("WARN") || result.startsWith("ERR"))
{
m_io_errcnt = 0;

m_notify |= (!okay || !cmd.startsWith("SendBytes"));
LOG(VB_RECORD, m_notify ? LOG_INFO : LOG_DEBUG,
LOC + QString("ProcessCommand('%1') = '%2'")
.arg(cmd).arg(result));
m_notify = false;

return okay;
}
else
LOG(VB_GENERAL, LOG_WARNING, LOC +
QString("External Recorder invalid response to '%1': '%2'")
.arg(cmd).arg(result));
}


if (result.size() < 1)
{
LOG(VB_GENERAL, LOG_WARNING, LOC +
QString("External Recorder did not respond to '%1'").arg(cmd));
if (++m_io_errcnt > 10) if (++m_io_errcnt > 10)
_error = true; _error = true;
return false; usleep(timeout);
} }
else
m_io_errcnt = 0;


m_notify |= (!result.startsWith("OK") || !cmd.startsWith("SendBytes")); return false;
LOG(VB_RECORD, m_notify ? LOG_INFO : LOG_DEBUG,
LOC + QString("ProcessCommand('%1') = '%2'").arg(cmd).arg(result));
m_notify = false;

return result.startsWith("OK");
} }


bool ExternalStreamHandler::CheckForError(void) bool ExternalStreamHandler::CheckForError(void)
Expand Down

0 comments on commit 2a66730

Please sign in to comment.