MCPcopy Create free account
hub / github.com/Martchus/syncthingtray / readData

Method readData

syncthingconnector/syncthingprocess.cpp:894–924  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

892}
893
894qint64 SyncthingProcess::readData(char *data, qint64 maxSize)
895{
896#ifdef LIB_SYNCTHING_CONNECTOR_BOOST_PROCESS
897 if (!m_process) {
898 return -1;
899 }
900 if (maxSize < 1) {
901 return 0;
902 }
903 if (!m_process->bytesBuffered) {
904 return 0; // do *not* invoke bufferOutput() here; an async read operation is already pending
905 }
906
907 const auto bytesAvailable = m_process->bytesBuffered - m_process->bytesRead;
908 if (bytesAvailable > static_cast<std::size_t>(maxSize)) {
909 std::memcpy(data, m_process->buffer + m_process->bytesRead, static_cast<std::size_t>(maxSize));
910 m_process->bytesRead += static_cast<std::size_t>(maxSize);
911 return maxSize;
912 } else {
913 std::memcpy(data, m_process->buffer + m_process->bytesRead, bytesAvailable);
914 m_process->bytesBuffered = 0;
915 m_process->bytesRead = 0;
916 QMetaObject::invokeMethod(this, "bufferOutput", Qt::QueuedConnection);
917 return static_cast<qint64>(bytesAvailable);
918 }
919#else
920 Q_UNUSED(data)
921 Q_UNUSED(maxSize)
922 return -1;
923#endif
924}
925
926qint64 SyncthingProcess::writeData(const char *data, qint64 len)
927{

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected