@@ -842,6 +842,57 @@ describe('tcp', () => {
842842
843843 expect ( received . value ) . toStrictEqual ( data ) ;
844844 } ) ;
845+
846+ test ( 'tcp packets are sent immediately without delay' , async ( ) => {
847+ const stack1 = await createStack ( ) ;
848+ const stack2 = await createStack ( ) ;
849+
850+ const tun1 = await stack1 . createTunInterface ( {
851+ ip : '192.168.1.1/24' ,
852+ } ) ;
853+
854+ const tun2 = await stack2 . createTunInterface ( {
855+ ip : '192.168.1.2/24' ,
856+ } ) ;
857+
858+ // Connect the two interfaces
859+ tun1 . readable . pipeTo ( tun2 . writable ) ;
860+ tun2 . readable . pipeTo ( tun1 . writable ) ;
861+
862+ const listener = await stack2 . listenTcp ( {
863+ port : 8080 ,
864+ } ) ;
865+
866+ const [ outbound , inbound ] = await Promise . all ( [
867+ stack1 . connectTcp ( {
868+ host : '192.168.1.2' ,
869+ port : 8080 ,
870+ } ) ,
871+ nextValue ( listener ) ,
872+ ] ) ;
873+
874+ const data = new Uint8Array ( [ 0x01 , 0x02 , 0x03 , 0x04 ] ) ;
875+
876+ const inboundReader = inbound . readable . getReader ( ) ;
877+ const outboundWriter = outbound . writable . getWriter ( ) ;
878+
879+ // Record start time
880+ const startTime = performance . now ( ) ;
881+
882+ // Write and read immediately
883+ await outboundWriter . write ( data ) ;
884+ const received = await inboundReader . read ( ) ;
885+
886+ // Record end time
887+ const endTime = performance . now ( ) ;
888+
889+ expect ( received . value ) . toStrictEqual ( data ) ;
890+
891+ // Check timing - with tcp_output enabled, this should be very fast
892+ // Without tcp_output, there would be a significant delay (~300ms)
893+ const elapsed = endTime - startTime ;
894+ expect ( elapsed ) . toBeCloseTo ( 0 , - 1 ) ;
895+ } ) ;
845896} ) ;
846897
847898describe ( 'udp' , ( ) => {
0 commit comments