Browse Source

Add CarlaPipeCommon::readlineblock function

tags/1.9.6
falkTX 10 years ago
parent
commit
c0d40ed9ae
2 changed files with 30 additions and 9 deletions
  1. +29
    -8
      source/utils/CarlaPipeUtils.cpp
  2. +1
    -1
      source/utils/CarlaPipeUtils.hpp

+ 29
- 8
source/utils/CarlaPipeUtils.cpp View File

@@ -508,7 +508,7 @@ bool CarlaPipeCommon::readNextLineAsBool(bool& value) noexcept
{ {
CARLA_SAFE_ASSERT_RETURN(pData->isReading, false); CARLA_SAFE_ASSERT_RETURN(pData->isReading, false);


if (const char* const msg = readline())
if (const char* const msg = readlineblock())
{ {
value = (std::strcmp(msg, "true") == 0); value = (std::strcmp(msg, "true") == 0);
delete[] msg; delete[] msg;
@@ -522,7 +522,7 @@ bool CarlaPipeCommon::readNextLineAsInt(int32_t& value) noexcept
{ {
CARLA_SAFE_ASSERT_RETURN(pData->isReading, false); CARLA_SAFE_ASSERT_RETURN(pData->isReading, false);


if (const char* const msg = readline())
if (const char* const msg = readlineblock())
{ {
value = std::atoi(msg); value = std::atoi(msg);
delete[] msg; delete[] msg;
@@ -536,7 +536,7 @@ bool CarlaPipeCommon::readNextLineAsUInt(uint32_t& value) noexcept
{ {
CARLA_SAFE_ASSERT_RETURN(pData->isReading, false); CARLA_SAFE_ASSERT_RETURN(pData->isReading, false);


if (const char* const msg = readline())
if (const char* const msg = readlineblock())
{ {
int32_t tmp = std::atoi(msg); int32_t tmp = std::atoi(msg);
delete[] msg; delete[] msg;
@@ -555,7 +555,7 @@ bool CarlaPipeCommon::readNextLineAsLong(int64_t& value) noexcept
{ {
CARLA_SAFE_ASSERT_RETURN(pData->isReading, false); CARLA_SAFE_ASSERT_RETURN(pData->isReading, false);


if (const char* const msg = readline())
if (const char* const msg = readlineblock())
{ {
value = std::atol(msg); value = std::atol(msg);
delete[] msg; delete[] msg;
@@ -569,7 +569,7 @@ bool CarlaPipeCommon::readNextLineAsULong(uint64_t& value) noexcept
{ {
CARLA_SAFE_ASSERT_RETURN(pData->isReading, false); CARLA_SAFE_ASSERT_RETURN(pData->isReading, false);


if (const char* const msg = readline())
if (const char* const msg = readlineblock())
{ {
int64_t tmp = std::atol(msg); int64_t tmp = std::atol(msg);
delete[] msg; delete[] msg;
@@ -588,7 +588,7 @@ bool CarlaPipeCommon::readNextLineAsFloat(float& value) noexcept
{ {
CARLA_SAFE_ASSERT_RETURN(pData->isReading, false); CARLA_SAFE_ASSERT_RETURN(pData->isReading, false);


if (const char* const msg = readline())
if (const char* const msg = readlineblock())
{ {
value = static_cast<float>(std::atof(msg)); value = static_cast<float>(std::atof(msg));
delete[] msg; delete[] msg;
@@ -602,7 +602,7 @@ bool CarlaPipeCommon::readNextLineAsDouble(double& value) noexcept
{ {
CARLA_SAFE_ASSERT_RETURN(pData->isReading, false); CARLA_SAFE_ASSERT_RETURN(pData->isReading, false);


if (const char* const msg = readline())
if (const char* const msg = readlineblock())
{ {
value = std::atof(msg); value = std::atof(msg);
delete[] msg; delete[] msg;
@@ -616,7 +616,7 @@ bool CarlaPipeCommon::readNextLineAsString(const char*& value) noexcept
{ {
CARLA_SAFE_ASSERT_RETURN(pData->isReading, false); CARLA_SAFE_ASSERT_RETURN(pData->isReading, false);


if (const char* const msg = readline())
if (const char* const msg = readlineblock())
{ {
value = msg; value = msg;
return true; return true;
@@ -692,6 +692,8 @@ bool CarlaPipeCommon::writeAndFixMsg(const char* const msg) noexcept
// internal // internal
const char* CarlaPipeCommon::readline() noexcept const char* CarlaPipeCommon::readline() noexcept
{ {
CARLA_SAFE_ASSERT_RETURN(pData->pipeRecv != INVALID_PIPE_VALUE, nullptr);

char c; char c;
char* ptr = pData->tmpBuf; char* ptr = pData->tmpBuf;
ssize_t ret; ssize_t ret;
@@ -744,6 +746,25 @@ const char* CarlaPipeCommon::readline() noexcept
return nullptr; return nullptr;
} }


const char* CarlaPipeCommon::readlineblock(const uint32_t timeOutMilliseconds) noexcept
{
const uint32_t timeoutEnd(juce::Time::getMillisecondCounter() + timeOutMilliseconds);

for (;;)
{
if (const char* const msg = readline())
return msg;

if (juce::Time::getMillisecondCounter() >= timeoutEnd)
break;

carla_msleep(5);
}

carla_stderr("readlineblock timed out");
return nullptr;
}

bool CarlaPipeCommon::writeMsgBuffer(const char* const msg, const std::size_t size) const noexcept bool CarlaPipeCommon::writeMsgBuffer(const char* const msg, const std::size_t size) const noexcept
{ {
// TESTING remove later (replace with trylock scope) // TESTING remove later (replace with trylock scope)


+ 1
- 1
source/utils/CarlaPipeUtils.hpp View File

@@ -82,7 +82,7 @@ private:


// internal // internal
const char* readline() noexcept; const char* readline() noexcept;
// internal
const char* readlineblock(const uint32_t timeOutMilliseconds = 50) noexcept;
bool writeMsgBuffer(const char* const msg, const std::size_t size) const noexcept; bool writeMsgBuffer(const char* const msg, const std::size_t size) const noexcept;


CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CarlaPipeCommon) CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CarlaPipeCommon)


Loading…
Cancel
Save