Commit 96f7ac78 authored by Robert Ricci's avatar Robert Ricci
Browse files

Fix a bug in which we were writing more than we intended to - also,

up the max write size to 8k (we still write the correct number of
bytes if the app makes a write bigger than this, we just do it in
a couple calls to write().)
parent 86c517e2
......@@ -172,6 +172,9 @@ void KernelTcp::addParam(ConnectionModelCommand const & param)
}
}
// MAX_WRITESIZE is in chars, and must be a multiple of 4
const int KernelTcp::MAX_WRITESIZE = 8192;
int KernelTcp::writeMessage(int size, WriteResult & result)
{
if (state == DISCONNECTED)
......@@ -205,10 +208,11 @@ int KernelTcp::writeMessage(int size, WriteResult & result)
int bytesToWrite;
int bytesWritten = 0;
for (bytesToWrite = size; bytesToWrite > 0; bytesToWrite -= MAX_WRITESIZE) {
int writeSize = min(MAX_WRITESIZE,bytesToWrite);
// Actually write the darn thing.
int error = send(peersock, &buffer[0], size, 0);
int error = send(peersock, &buffer[0], writeSize, 0);
logWrite(CONNECTION_MODEL,"Tried to write %d bytes, actually wrote %d",
size, error);
writeSize, error);
if (error == 0)
{
......@@ -226,7 +230,7 @@ int KernelTcp::writeMessage(int size, WriteResult & result)
logWrite(CONNECTION_MODEL,"Buffer is full");
result.bufferFull = true;
// No point in trying more writes
return error;
return bytesWritten + error;
}
else
{
......
......@@ -30,8 +30,7 @@ private:
int receiveBufferSize;
int maxSegmentSize;
int useNagles;
// MAX_WRITESIZE is in chars, and must be a multiple of 4
static const int MAX_WRITESIZE = 2048;
static const int MAX_WRITESIZE;
public:
static pcap_t * pcapDescriptor;
static int pcapfd;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment