Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure that all bytes of a response message are written #262

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions webserver/core/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,15 +180,27 @@ int listenToClient(int client_fd, unsigned char *buffer)
//-----------------------------------------------------------------------------
void processMessage(unsigned char *buffer, int bufferSize, int client_fd, int protocol_type)
{
int messageSize = 0;
if (protocol_type == MODBUS_PROTOCOL)
{
int messageSize = processModbusMessage(buffer, bufferSize);
write(client_fd, buffer, messageSize);
messageSize = processModbusMessage(buffer, bufferSize);
}
else if (protocol_type == ENIP_PROTOCOL)
{
int messageSize = processEnipMessage(buffer, bufferSize);
write(client_fd, buffer, messageSize);
messageSize = processEnipMessage(buffer, bufferSize);
}
while (messageSize > 0)
{
ssize_t bytesWritten = write(client_fd, buffer, messageSize);
if (bytesWritten < 0)
{
char log_msg[1000];
sprintf(log_msg, "Server: Error writing response: %zd\n", bytesWritten);
log(log_msg);
break;
}
buffer += bytesWritten;
messageSize -= bytesWritten;
}
}

Expand Down