lwip - Added windowing to tcp packet pressure tests

Despite being able to buffer an arbitrary stream of data,
TCP send is still limited by the available buffer space in the
network stack. Errors from TCP send are perfectly reasonable
and should be handled by reducing the buffer that is attempted.
pull/3265/head
Christopher Haster 2016-11-17 12:39:08 -06:00
parent 2da71a7f87
commit 51a093d6d8
2 changed files with 36 additions and 8 deletions

View File

@ -156,29 +156,40 @@ int main() {
RandSeq rx_seq;
size_t rx_count = 0;
size_t tx_count = 0;
size_t window = buffer_size;
while (tx_count < size || rx_count < size) {
// Send out data
if (tx_count < size) {
size_t chunk_size = size - tx_count;
if (chunk_size > buffer_size) {
chunk_size = buffer_size;
if (chunk_size > window) {
chunk_size = window;
}
tx_seq.buffer(buffer, chunk_size);
int td = sock.send(buffer, chunk_size);
TEST_ASSERT(td > 0 || td == NSAPI_ERROR_WOULD_BLOCK);
if (td > 0) {
if (MBED_CFG_TCP_CLIENT_PACKET_PRESSURE_DEBUG) {
printf("TCP: tx -> %d\r\n", td);
}
tx_seq.skip(td);
tx_count += td;
} else if (td != NSAPI_ERROR_WOULD_BLOCK) {
// We may fail to send because of buffering issues,
// cut buffer in half
if (window > MBED_CFG_TCP_CLIENT_PACKET_PRESSURE_MIN) {
window /= 2;
}
if (MBED_CFG_TCP_CLIENT_PACKET_PRESSURE_DEBUG) {
printf("TCP: Not sent (%d), window = %d\r\n", td, window);
}
}
}
// Verify recieved data
if (rx_count < size) {
while (rx_count < size) {
int rd = sock.recv(buffer, buffer_size);
TEST_ASSERT(rd > 0 || rd == NSAPI_ERROR_WOULD_BLOCK);
if (rd > 0) {
@ -189,6 +200,8 @@ int main() {
TEST_ASSERT_EQUAL(0, diff);
rx_seq.skip(rd);
rx_count += rd;
} else if (rd == NSAPI_ERROR_WOULD_BLOCK) {
break;
}
}
}

View File

@ -153,18 +153,19 @@ public:
RandSeq rx_seq;
size_t rx_count = 0;
size_t tx_count = 0;
size_t window = buffer_size;
while (tx_count < size || rx_count < size) {
// Send out data
if (tx_count < size) {
size_t chunk_size = size - tx_count;
if (chunk_size > buffer_size) {
chunk_size = buffer_size;
if (chunk_size > window) {
chunk_size = window;
}
tx_seq.buffer(buffer, chunk_size);
int td = sock.send(buffer, chunk_size);
TEST_ASSERT(td > 0 || td == NSAPI_ERROR_WOULD_BLOCK);
if (td > 0) {
if (MBED_CFG_TCP_CLIENT_PACKET_PRESSURE_DEBUG) {
iomutex.lock();
@ -173,11 +174,23 @@ public:
}
tx_seq.skip(td);
tx_count += td;
} else if (td != NSAPI_ERROR_WOULD_BLOCK) {
// We may fail to send because of buffering issues,
// cut buffer in half
if (window > MBED_CFG_TCP_CLIENT_PACKET_PRESSURE_MIN) {
window /= 2;
}
if (MBED_CFG_TCP_CLIENT_PACKET_PRESSURE_DEBUG) {
iomutex.lock();
printf("TCP: Not sent (%d), window = %d\r\n", td, window);
iomutex.unlock();
}
}
}
// Verify recieved data
if (rx_count < size) {
while (rx_count < size) {
int rd = sock.recv(buffer, buffer_size);
TEST_ASSERT(rd > 0 || rd == NSAPI_ERROR_WOULD_BLOCK);
if (rd > 0) {
@ -190,6 +203,8 @@ public:
TEST_ASSERT_EQUAL(0, diff);
rx_seq.skip(rd);
rx_count += rd;
} else if (rd == NSAPI_ERROR_WOULD_BLOCK) {
break;
}
}
}