Skip to content

Commit eca4f22

Browse files
committed
feat: add test to check tcp delay and comment code to reproduce issue
1 parent 81c8736 commit eca4f22

File tree

2 files changed

+43
-4
lines changed

2 files changed

+43
-4
lines changed

packages/tcpip/src/stack.test.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -842,6 +842,45 @@ describe('tcp', () => {
842842

843843
expect(received.value).toStrictEqual(data);
844844
});
845+
846+
test('tcp packets are sent immediately without delay', async () => {
847+
const stack = await createStack();
848+
849+
const listener = await stack.listenTcp({
850+
host: '127.0.0.1',
851+
port: 8080,
852+
});
853+
854+
const [outbound, inbound] = await Promise.all([
855+
stack.connectTcp({
856+
host: '127.0.0.1',
857+
port: 8080,
858+
}),
859+
nextValue(listener),
860+
]);
861+
862+
const data = new Uint8Array([0x01, 0x02, 0x03, 0x04]);
863+
864+
const inboundReader = inbound.readable.getReader();
865+
const outboundWriter = outbound.writable.getWriter();
866+
867+
// Record start time
868+
const startTime = performance.now();
869+
870+
// Write and read immediately
871+
await outboundWriter.write(data);
872+
const received = await inboundReader.read();
873+
874+
// Record end time
875+
const endTime = performance.now();
876+
877+
expect(received.value).toStrictEqual(data);
878+
879+
// Check timing - with tcp_output enabled, this should be very fast
880+
// Without tcp_output, there would be a significant delay (~300ms)
881+
const elapsed = endTime - startTime;
882+
expect(elapsed).toBeLessThan(100);
883+
});
845884
});
846885

847886
describe('udp', () => {

packages/tcpip/wasm/tcp.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ uint16_t send_tcp_chunk(struct tcp_pcb *conn, uint8_t *chunk, uint16_t length) {
3232
}
3333

3434
// Force sending chunks immediately
35-
err_t out_result = tcp_output(conn);
36-
if (out_result != ERR_OK) {
37-
return 0;
38-
}
35+
// err_t out_result = tcp_output(conn);
36+
// if (out_result != ERR_OK) {
37+
// return 0;
38+
// }
3939

4040
return bytes_to_send;
4141
}

0 commit comments

Comments
 (0)