@@ -89,7 +89,7 @@ class OwnedSocket {
8989};
9090
9191struct SockaddrStorage {
92- SockaddrStorage () : storage() , len(sizeof (storage)) {}
92+ SockaddrStorage () : storage(), len(sizeof (storage)) {}
9393
9494 int family () const { return storage.ss_family ; }
9595
@@ -1063,3 +1063,36 @@ TEST(BIOTest, InvokeConnectCallback) {
10631063} // namespace
10641064
10651065INSTANTIATE_TEST_SUITE_P (All, BIOPairTest, testing::Values(false , true ));
1066+
1067+ TEST (BIOTest, ReadWriteEx) {
1068+ bssl::UniquePtr<BIO> bio (BIO_new (BIO_s_mem ()));
1069+ ASSERT_TRUE (bio);
1070+
1071+ size_t written = 0 ;
1072+ ASSERT_TRUE (BIO_write_ex (bio.get (), " abcdef" , 6 , &written));
1073+ EXPECT_EQ (written, (size_t )6 );
1074+
1075+ char buf[32 ];
1076+ size_t read = 0 ;
1077+ ASSERT_TRUE (BIO_read_ex (bio.get (), buf, sizeof (buf), &read));
1078+ EXPECT_GT (read, (size_t )0 );
1079+ EXPECT_EQ (Bytes (buf, read), Bytes (" abcdef" ));
1080+
1081+ // Test NULL |written_bytes| behavior works.
1082+ read = 0 ;
1083+ ASSERT_TRUE (BIO_write_ex (bio.get (), " ghilmnop" , 8 , nullptr ));
1084+ ASSERT_TRUE (BIO_read_ex (bio.get (), buf, sizeof (buf), &read));
1085+ EXPECT_GT (read, (size_t )0 );
1086+ EXPECT_EQ (Bytes (buf, read), Bytes (" ghilmnop" ));
1087+
1088+ // Test NULL |read_bytes| behavior fails.
1089+ ASSERT_TRUE (BIO_write_ex (bio.get (), " ghilmnop" , 8 , nullptr ));
1090+ ASSERT_FALSE (BIO_read_ex (bio.get (), buf, sizeof (buf), nullptr ));
1091+
1092+ // Test that |BIO_write/read_ex| align with their non-ex counterparts, when
1093+ // encountering NULL data.
1094+ EXPECT_FALSE (BIO_write (bio.get (), nullptr , 0 ));
1095+ EXPECT_FALSE (BIO_write_ex (bio.get (), nullptr , 0 , &written));
1096+ EXPECT_FALSE (BIO_read (bio.get (), nullptr , 0 ));
1097+ EXPECT_FALSE (BIO_read_ex (bio.get (), nullptr , 0 , &read));
1098+ }
0 commit comments