From f89b4b3b26bec6b25bd56d7505d7fb831b173b9e Mon Sep 17 00:00:00 2001 From: winlin Date: Sat, 21 Mar 2020 20:20:40 +0800 Subject: [PATCH] For #1651, fix return pnwrite of srs_write_large_iovs. 3.0.135 --- README.md | 2 + trunk/src/core/srs_core_version3.hpp | 2 +- trunk/src/protocol/srs_protocol_utility.cpp | 2 +- trunk/src/utest/srs_utest_protocol.cpp | 64 ++++++++++++++++++++- 4 files changed, 66 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index b56e9edaf..2cd74f917 100755 --- a/README.md +++ b/README.md @@ -146,6 +146,7 @@ For previous versions, please read: ## V3 changes +* v3.0, 2020-03-21, For [#1651][bug #1651], fix return pnwrite of srs_write_large_iovs. 3.0.135 * v3.0, 2020-03-18, [3.0 beta3(3.0.134)][r3.0b3] released. 122509 lines. * v3.0, 2020-03-12, For [#1635][bug #1635], inotify watch ConfigMap for reload. 3.0.134 * v3.0, 2020-03-12, For [#1635][bug #1635], support auto reaload config by inotify. 3.0.129 @@ -1676,6 +1677,7 @@ Winlin [bug #1594]: https://github.com/ossrs/srs/issues/1594 [bug #1630]: https://github.com/ossrs/srs/issues/1630 [bug #1635]: https://github.com/ossrs/srs/issues/1635 +[bug #1651]: https://github.com/ossrs/srs/issues/1651 [bug #yyyyyyyyyyyyy]: https://github.com/ossrs/srs/issues/yyyyyyyyyyyyy [exo #828]: https://github.com/google/ExoPlayer/pull/828 diff --git a/trunk/src/core/srs_core_version3.hpp b/trunk/src/core/srs_core_version3.hpp index 5ff02aa5a..85bd342c0 100644 --- a/trunk/src/core/srs_core_version3.hpp +++ b/trunk/src/core/srs_core_version3.hpp @@ -24,6 +24,6 @@ #ifndef SRS_CORE_VERSION3_HPP #define SRS_CORE_VERSION3_HPP -#define SRS_VERSION3_REVISION 134 +#define SRS_VERSION3_REVISION 135 #endif diff --git a/trunk/src/protocol/srs_protocol_utility.cpp b/trunk/src/protocol/srs_protocol_utility.cpp index 56294defb..2582a0c1a 100644 --- a/trunk/src/protocol/srs_protocol_utility.cpp +++ b/trunk/src/protocol/srs_protocol_utility.cpp @@ -336,7 +336,7 @@ srs_error_t srs_write_large_iovs(ISrsProtocolReadWriter* skt, iovec* iovs, int s #endif // send in a time. - if (size < limits) { + if (size <= limits) { if ((err = skt->writev(iovs, size, pnwrite)) != srs_success) { return srs_error_wrap(err, "writev"); } diff --git a/trunk/src/utest/srs_utest_protocol.cpp b/trunk/src/utest/srs_utest_protocol.cpp index 0e952cf68..2535b6fd2 100644 --- a/trunk/src/utest/srs_utest_protocol.cpp +++ b/trunk/src/utest/srs_utest_protocol.cpp @@ -230,8 +230,6 @@ srs_error_t MockBufferIO::writev(const iovec *iov, int iov_size, ssize_t* nwrite total += writen; } - sbytes += total; - if (nwrite) { *nwrite = total; } @@ -6412,3 +6410,65 @@ VOID TEST(ProtocolKbpsTest, RAWStatistic) } } +VOID TEST(ProtocolKbpsTest, WriteLargeIOVs) +{ + srs_error_t err; + + if (true) { + iovec iovs[1]; + iovs[0].iov_base = (char*)"Hello"; + iovs[0].iov_len = 5; + + MockBufferIO io; + ssize_t nn = 0; + HELPER_EXPECT_SUCCESS(srs_write_large_iovs(&io, iovs, 1, &nn)); + EXPECT_EQ(5, nn); + EXPECT_EQ(5, io.sbytes); + } + + if (true) { + iovec iovs[1024]; + int nn_iovs = (int)(sizeof(iovs)/sizeof(iovec)); + for (int i = 0; i < nn_iovs; i++) { + iovs[i].iov_base = (char*)"Hello"; + iovs[i].iov_len = 5; + } + + MockBufferIO io; + ssize_t nn = 0; + HELPER_EXPECT_SUCCESS(srs_write_large_iovs(&io, iovs, nn_iovs, &nn)); + EXPECT_EQ(5 * nn_iovs, nn); + EXPECT_EQ(5 * nn_iovs, io.sbytes); + } + + if (true) { + iovec iovs[1025]; + int nn_iovs = (int)(sizeof(iovs)/sizeof(iovec)); + for (int i = 0; i < nn_iovs; i++) { + iovs[i].iov_base = (char*)"Hello"; + iovs[i].iov_len = 5; + } + + MockBufferIO io; + ssize_t nn = 0; + HELPER_EXPECT_SUCCESS(srs_write_large_iovs(&io, iovs, nn_iovs, &nn)); + EXPECT_EQ(5 * nn_iovs, nn); + EXPECT_EQ(5 * nn_iovs, io.sbytes); + } + + if (true) { + iovec iovs[4096]; + int nn_iovs = (int)(sizeof(iovs)/sizeof(iovec)); + for (int i = 0; i < nn_iovs; i++) { + iovs[i].iov_base = (char*)"Hello"; + iovs[i].iov_len = 5; + } + + MockBufferIO io; + ssize_t nn = 0; + HELPER_EXPECT_SUCCESS(srs_write_large_iovs(&io, iovs, nn_iovs, &nn)); + EXPECT_EQ(5 * nn_iovs, nn); + EXPECT_EQ(5 * nn_iovs, io.sbytes); + } +} +