Open IOTeule opened 2 years ago
I think, this should fix it:
void Client::receiveTask() {
while(isConnected()) {
const fd_wait::Result waitResult = fd_wait::waitFor(_sockfd);
if (waitResult == fd_wait::Result::FAILURE) {
throw std::runtime_error(strerror(errno));
} else if (waitResult == fd_wait::Result::TIMEOUT) {
continue;
}
char receivedMessage[MAX_PACKET_SIZE];
const size_t numOfBytesReceived = recv(_sockfd.get(), receivedMessage, MAX_PACKET_SIZE, 0);
if(numOfBytesReceived < 1) {
const bool clientClosedConnection = (numOfBytesReceived == 0);
std::string disconnectionMessage;
if (clientClosedConnection) {
disconnectionMessage = "Client closed connection";
} else {
disconnectionMessage = strerror(errno);
}
setConnected(false);
publishEvent(ClientEvent::DISCONNECTED, disconnectionMessage);
return;
} else {
// fix here
receivedMessage[numOfBytesReceived] = '\0';
// fix here
publishEvent(ClientEvent::INCOMING_MSG, receivedMessage);
}
}
}
see PR
There seems to be a bug in the server example about incoming msg size.
To reproduce:
seems to be a bug in message size