My code depends on the following function for reading from a socket:
int readSocket( std::string &sockResponseString) {
auto can_read = [](int s) -> bool {
fd_set read_set;
FD_ZERO(&read_set);
FD_SET(s, &read_set);
struct timeval timeout {};
int rc = select(s + 1, &read_set, NULL, NULL, &timeout);
return (rc == 1) && FD_ISSET(s, &read_set);
};
auto do_read = [&sockResponseString](int s) -> bool {
char buf[BUFSIZ];
int nbytes = recv(s, buf, sizeof(buf), 0);
if (nbytes <= 0)
return false;
sockResponseString += std::string(buf, static_cast<size_t>(nbytes));
return true;
};
sockResponseString.clear();
bool done{};
while (!done) {
if (can_read(Master_sfd) && do_read(Master_sfd)) {
while (!done) {
if (!can_read(Master_sfd))
done = true;
do_read(Master_sfd);
}
}
}
return static_cast<int>(sockResponseString.size());
};
This function does exactly what is needed and compiles without errors.
It is strange however that I am not able to inspect the sockResponseString in the debugger.
After right-clicking this variable in the debugger and selecting 'display as array', these message appear in the lower part of the debug view:
Multiple errors reported.
1) Failed to execute MI command:
-var-create - * (*((sockResponseString)+0)@1)
Error message from debugger back end:
No symbol "operator+" in current context.
2) Unable to create variable object
3) Failed to execute MI command:
-data-evaluate-expression (*((sockResponseString)+0)@1)
Error message from debugger back end:
No symbol "operator+" in current context.
4) Failed to execute MI command:
-var-create - * (*((sockResponseString)+0)@1)
Error message from debugger back end:
No symbol "operator+" in current context.
The C++ - community could not tell me what this means.
Do I have to change my code?
Ben