You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
stream_client_socket::operator>> forms invalid std::string on write #91
The operator>> of socket forms incorrect std::string.
If I try to read message from socket with >> I get "nothing", because std::string was not resized properly. See the code snippet below:
// Assume that client sends "test message" after connection
libsocket::inet_stream_server server("127.0.0.1", "8080", LIBSOCKET_IPv4);
auto client = server.accept2();
std::string received_msg;
*client >> received_msg;
// Next line prints `[SERVER] Received: `
std::cout << "[SERVER] Received: " << received_msg << std::endl;
// Next line prints `[SERVER] Received: test message`
std::cout << "[SERVER] Received: " << received_msg.data() << std::endl;
if (read_bytes < static_cast<ssize_t>(dest.size()))
The condition read_bytes < static_cast<ssize_t>(dest.size()) doesn't work for case, when dest is a newly created std::string and read_bytes is greater than 0.
I suggest to remove if statement and always resize dest to read_bytes size or just invert the condition.
Activity