This is an automated email from the ASF dual-hosted git repository. oknet pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/trafficserver.git
The following commit(s) were added to refs/heads/master by this push: new 2449069 Correct handle the value return from mgmt socket read and write (#6220) 2449069 is described below commit 244906904ac08c25924318e4b0aecdf1292302b3 Author: Oknet Xu <xuc...@skyguard.com.cn> AuthorDate: Thu Nov 21 21:22:06 2019 +0800 Correct handle the value return from mgmt socket read and write (#6220) --- mgmt/utils/MgmtUtils.cc | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/mgmt/utils/MgmtUtils.cc b/mgmt/utils/MgmtUtils.cc index aa007af..010fc7b 100644 --- a/mgmt/utils/MgmtUtils.cc +++ b/mgmt/utils/MgmtUtils.cc @@ -70,11 +70,7 @@ mgmt_readline(int soc, char *buf, int maxlen) break; } } else if (rc == 0) { - if (n == 1) { /* EOF */ - return 0; - } else { - break; - } + return n; } else { /* Error */ if (errno == ECONNRESET || errno == EPIPE) { return n ? n : 0; @@ -105,24 +101,39 @@ mgmt_readline(int soc, char *buf, int maxlen) int mgmt_writeline(int soc, const char *data, int nbytes) { - int nleft, n; + int nleft, n = 0; const char *tmp = data; nleft = nbytes; while (nleft > 0) { int nwritten = write_socket(soc, tmp, nleft); - if (nwritten <= 0) { /* Error or nothing written */ + if (nwritten == 0) { // Nothing written + mgmt_sleep_msec(1); + continue; + } else if (nwritten < 0) { // Error + if (mgmt_transient_error()) { + mgmt_sleep_msec(1); + continue; + } + return nwritten; } nleft -= nwritten; tmp += nwritten; } - if ((n = write_socket(soc, "\n", 1)) <= 0) { /* Terminating newline */ - if (n < 0) { + while (n != 1) { + n = write_socket(soc, "\n", 1); /* Terminating newline */ + if (n == 0) { + mgmt_sleep_msec(1); + continue; + } else if (n < 0) { // Error + if (mgmt_transient_error()) { + mgmt_sleep_msec(1); + continue; + } + return n; - } else { - return (nbytes - nleft); } } @@ -147,6 +158,7 @@ mgmt_read_pipe(int fd, char *buf, int bytes_to_read) while (bytes_to_read > 0) { int err = read_socket(fd, p, bytes_to_read); if (err == 0) { + // return 0 if partial read. return err; } else if (err < 0) { // Turn ECONNRESET into EOF. @@ -188,7 +200,10 @@ mgmt_write_pipe(int fd, char *buf, int bytes_to_write) while (bytes_to_write > 0) { int err = write_socket(fd, p, bytes_to_write); if (err == 0) { - return err; + // Where this volume of IEEE Std 1003.1-2001 requires -1 to be returned and errno set to [EAGAIN], + // most historical implementations return zero for write(2) + mgmt_sleep_msec(1); + continue; } else if (err < 0) { if (mgmt_transient_error()) { mgmt_sleep_msec(1);