itas109 / CSerialPort

CSerialPort - lightweight cross-platform serial port library for C++/C/C#/Java/Python/Node.js/Electron
https://blog.csdn.net/itas109/article/details/84282860
Other
710 stars 337 forks source link

ibuffer read有效性判断 #88

Open linjc0 opened 3 months ago

linjc0 commented 3 months ago

改成下面的方式,在运行过程中添加有效性判断 virtual int read(T *data, unsigned int size) { if (size > m_maxBufferSize) { size = m_maxBufferSize; }

    unsigned int readDataSize = 0;
    while ((!isEmpty()) && (readDataSize < size))
    {
        data[readDataSize] = m_buffer[m_head & (m_maxBufferSize - 1)];
        ++readDataSize;
        m_head = (m_head + 1) & m_maxMirrorBufferIndex;
    }

    return readDataSize;
}
itas109 commented 3 months ago

目前的读取方式会遇到什么问题吗