Skip to content

Commit 1144ab0

Browse files
committed
bitfocus: put read data from socket in queue
1 parent 4bb9766 commit 1144ab0

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

src/plugins/score-plugin-protocols/Protocols/Bitfocus/BitfocusContext.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ struct module_handler_base : public QObject
109109
struct module_handler_base : public QObject
110110
{
111111
char buf[16 * 4096]{};
112+
std::vector<char> queue;
112113
QProcess process{};
113114
QSocketNotifier* socket{};
114115
int pfd[2]{};

src/plugins/score-plugin-protocols/Protocols/Bitfocus/BitfocusContext.unix.cpp

+10-3
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,19 @@ void module_handler_base::on_read(QSocketDescriptor, QSocketNotifier::Type)
4343
ssize_t rl = ::read(pfd[0], buf, sizeof(buf));
4444
if(rl <= 0)
4545
return;
46-
char* pos = buf;
47-
char* idx = buf;
48-
char* const end = pos + rl;
46+
queue.insert(queue.end(), buf, buf + rl);
47+
48+
char* pos = queue.data();
49+
char* idx = queue.data();
50+
char* last_message_start = queue.data();
51+
char* const end = queue.data() + queue.size();
52+
4953
do
5054
{
5155
idx = std::find(pos, end, '\n');
5256
if(idx < end)
5357
{
58+
last_message_start = idx;
5459
std::ptrdiff_t diff = idx - pos;
5560
std::string_view message(pos, diff);
5661
// std::cerr << "\n=========================\n <-- " << message << "\n";
@@ -59,6 +64,8 @@ void module_handler_base::on_read(QSocketDescriptor, QSocketNotifier::Type)
5964
continue;
6065
}
6166
} while(idx < end);
67+
intptr_t processed_count = last_message_start - queue.data();
68+
queue.erase(queue.begin(), queue.begin() + processed_count);
6269
}
6370

6471
void module_handler_base::do_write(std::string_view res)

0 commit comments

Comments
 (0)