@@ -679,6 +679,55 @@ TEST_F(tls, splice_dec_cmsg_to_pipe)
679679 EXPECT_EQ (memcmp (test_str , buf , send_len ), 0 );
680680}
681681
682+ TEST_F (tls , recv_and_splice )
683+ {
684+ int send_len = TLS_PAYLOAD_MAX_LEN ;
685+ char mem_send [TLS_PAYLOAD_MAX_LEN ];
686+ char mem_recv [TLS_PAYLOAD_MAX_LEN ];
687+ int half = send_len / 2 ;
688+ int p [2 ];
689+
690+ ASSERT_GE (pipe (p ), 0 );
691+ EXPECT_EQ (send (self -> fd , mem_send , send_len , 0 ), send_len );
692+ /* Recv hald of the record, splice the other half */
693+ EXPECT_EQ (recv (self -> cfd , mem_recv , half , MSG_WAITALL ), half );
694+ EXPECT_EQ (splice (self -> cfd , NULL , p [1 ], NULL , half , SPLICE_F_NONBLOCK ),
695+ half );
696+ EXPECT_EQ (read (p [0 ], & mem_recv [half ], half ), half );
697+ EXPECT_EQ (memcmp (mem_send , mem_recv , send_len ), 0 );
698+ }
699+
700+ TEST_F (tls , peek_and_splice )
701+ {
702+ int send_len = TLS_PAYLOAD_MAX_LEN ;
703+ char mem_send [TLS_PAYLOAD_MAX_LEN ];
704+ char mem_recv [TLS_PAYLOAD_MAX_LEN ];
705+ int chunk = TLS_PAYLOAD_MAX_LEN / 4 ;
706+ int n , i , p [2 ];
707+
708+ memrnd (mem_send , sizeof (mem_send ));
709+
710+ ASSERT_GE (pipe (p ), 0 );
711+ for (i = 0 ; i < 4 ; i ++ )
712+ EXPECT_EQ (send (self -> fd , & mem_send [chunk * i ], chunk , 0 ),
713+ chunk );
714+
715+ EXPECT_EQ (recv (self -> cfd , mem_recv , chunk * 5 / 2 ,
716+ MSG_WAITALL | MSG_PEEK ),
717+ chunk * 5 / 2 );
718+ EXPECT_EQ (memcmp (mem_send , mem_recv , chunk * 5 / 2 ), 0 );
719+
720+ n = 0 ;
721+ while (n < send_len ) {
722+ i = splice (self -> cfd , NULL , p [1 ], NULL , send_len - n , 0 );
723+ EXPECT_GT (i , 0 );
724+ n += i ;
725+ }
726+ EXPECT_EQ (n , send_len );
727+ EXPECT_EQ (read (p [0 ], mem_recv , send_len ), send_len );
728+ EXPECT_EQ (memcmp (mem_send , mem_recv , send_len ), 0 );
729+ }
730+
682731TEST_F (tls , recvmsg_single )
683732{
684733 char const * test_str = "test_recvmsg_single" ;
0 commit comments