Skip to content

Commit

Permalink
Fix return value of doio_n() when count is larger than the rest
Browse files Browse the repository at this point in the history
data in socket.

Signed-off-by: Yifan Yuan <tuji.yyf@alibaba-inc.com>

.
  • Loading branch information
BigVan authored and beef9999 committed Sep 1, 2023
1 parent 779751a commit 4fe2f3b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
11 changes: 7 additions & 4 deletions net/basic_socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,22 +108,25 @@ __FORCE_INLINE__ int doio(IOCB iocb, WAIT waitcb) {

template <typename IOCB>
__FORCE_INLINE__ ssize_t doio_n(void *&buf, size_t &count, IOCB iocb) {
auto count0 = count;
ssize_t n = 0;
while (count > 0) {
ssize_t ret = iocb();
if (ret <= 0) return ret;
if (ret < 0) return ret; // error
if (ret == 0) break; // EOF
(char *&)buf += ret;
count -= ret;
n += ret;
}
return count0;
return n;
}

template <typename IOCB>
__FORCE_INLINE__ ssize_t doiov_n(iovector_view &v, IOCB iocb) {
ssize_t count = 0;
while (v.iovcnt > 0) {
ssize_t ret = iocb();
if (ret <= 0) return ret;
if (ret < 0) return ret;
if (ret == 0) break;
count += ret;

uint64_t bytes = ret;
Expand Down
2 changes: 1 addition & 1 deletion net/security-context/test/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ int close_test_handler_during_read(void* arg, net::ISocketStream* stream) {
auto ret = ss->read(buf, 6);
LOG_INFO("AFTER READ");
// since client will shutdown, return value should be 0
EXPECT_EQ(0, ret);
EXPECT_EQ(3, ret);
LOG_INFO(VALUE(buf));
LOG_INFO("BEFORE WRITE");
ss->write(buffer, 1048576);
Expand Down

0 comments on commit 4fe2f3b

Please sign in to comment.