Browse Source

Fix sending big messages via pipe; Cleanup

tags/1.9.7
falkTX 9 years ago
parent
commit
8984c0971b
2 changed files with 31 additions and 23 deletions
  1. +6
    -3
      source/bridges-ui/CarlaBridgeUI.cpp
  2. +25
    -20
      source/utils/CarlaPipeUtils.cpp

+ 6
- 3
source/bridges-ui/CarlaBridgeUI.cpp View File

@@ -182,11 +182,11 @@ bool CarlaBridgeUI::msgReceived(const char* const msg) noexcept

if (std::strcmp(msg, "atom") == 0)
{
uint32_t index, size;
uint32_t index, atomTotalSize;
const char* base64atom;

CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(index), true);
CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(size), true);
CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(atomTotalSize), true);
CARLA_SAFE_ASSERT_RETURN(readNextLineAsString(base64atom), true);

std::vector<uint8_t> chunk(carla_getChunkFromBase64String(base64atom));
@@ -194,7 +194,10 @@ bool CarlaBridgeUI::msgReceived(const char* const msg) noexcept
CARLA_SAFE_ASSERT_RETURN(chunk.size() >= sizeof(LV2_Atom), true);

const LV2_Atom* const atom((const LV2_Atom*)chunk.data());
CARLA_SAFE_ASSERT_RETURN(lv2_atom_total_size(atom) == chunk.size(), true);
const uint32_t atomTotalSizeCheck(lv2_atom_total_size(atom));

CARLA_SAFE_ASSERT_RETURN(atomTotalSizeCheck == atomTotalSize, true);
CARLA_SAFE_ASSERT_RETURN(atomTotalSizeCheck == chunk.size(), true);

dspAtomReceived(index, atom);
return true;


+ 25
- 20
source/utils/CarlaPipeUtils.cpp View File

@@ -799,12 +799,12 @@ bool CarlaPipeCommon::writeAndFixMessage(const char* const msg) const noexcept
if (fixedMsg[size-1] == '\r')
{
fixedMsg[size-1] = '\n';
fixedMsg[size] = '\0';
fixedMsg[size ] = '\0';
fixedMsg[size+1] = '\0';
}
else
{
fixedMsg[size] = '\n';
fixedMsg[size ] = '\n';
fixedMsg[size+1] = '\0';
}
}
@@ -962,7 +962,8 @@ void CarlaPipeCommon::writeLv2AtomMessage(const uint32_t index, const LV2_Atom*
char tmpBuf[0xff+1];
tmpBuf[0xff] = '\0';

CarlaString base64atom(CarlaString::asBase64(atom, lv2_atom_total_size(atom)));
const uint32_t atomTotalSize(lv2_atom_total_size(atom));
CarlaString base64atom(CarlaString::asBase64(atom, atomTotalSize));

const CarlaMutexLocker cml(pData->writeLock);

@@ -972,7 +973,7 @@ void CarlaPipeCommon::writeLv2AtomMessage(const uint32_t index, const LV2_Atom*
std::snprintf(tmpBuf, 0xff, "%i\n", index);
_writeMsgBuffer(tmpBuf, std::strlen(tmpBuf));

std::snprintf(tmpBuf, 0xff, "%i\n", atom->size);
std::snprintf(tmpBuf, 0xff, "%i\n", atomTotalSize);
_writeMsgBuffer(tmpBuf, std::strlen(tmpBuf));

writeAndFixMessage(base64atom.buffer());
@@ -1016,7 +1017,7 @@ const char* CarlaPipeCommon::_readline() const noexcept

pData->tmpStr.clear();

for (int i=0; i < 0xff; ++i)
for (int i=0; i<0xff; ++i)
{
try {
#ifdef CARLA_OS_WIN
@@ -1027,6 +1028,9 @@ const char* CarlaPipeCommon::_readline() const noexcept
#endif
} CARLA_SAFE_EXCEPTION_BREAK("CarlaPipeCommon::readline() - read");

//if (ret == 0 || c == '\n')
// break;

if (ret == 1 && c != '\n')
{
if (c == '\r')
@@ -1037,30 +1041,31 @@ const char* CarlaPipeCommon::_readline() const noexcept
if (i+1 == 0xff)
{
i = 0;
ptr = pData->tmpBuf;
pData->tmpStr += pData->tmpBuf;
}

continue;
}

if (pData->tmpStr.isNotEmpty() || ptr != pData->tmpBuf || ret == 1)
{
if (ptr != pData->tmpBuf)
{
*ptr = '\0';
pData->tmpStr += pData->tmpBuf;
ptr = pData->tmpBuf;
}

try {
return pData->tmpStr.dup();
} CARLA_SAFE_EXCEPTION_RETURN("CarlaPipeCommon::readline() - dup", nullptr);
continue;
}

break;
}

return nullptr;
if (ptr != pData->tmpBuf)
{
*ptr = '\0';
pData->tmpStr += pData->tmpBuf;
}
else if (pData->tmpStr.isEmpty())
{
// some error
return nullptr;
}

try {
return pData->tmpStr.dup();
} CARLA_SAFE_EXCEPTION_RETURN("CarlaPipeCommon::readline() - dup", nullptr);
}

const char* CarlaPipeCommon::_readlineblock(const uint32_t timeOutMilliseconds) const noexcept


Loading…
Cancel
Save