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 committed Aug 31, 2023
1 parent 779751a commit c4e243e
Showing 1 changed file with 7 additions and 4 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

0 comments on commit c4e243e

Please sign in to comment.