-
Notifications
You must be signed in to change notification settings - Fork 844
Correct handle the value return from mgmt socket read and write (#6220) #6220
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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); | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Returns: num bytes not written |
||
| } | ||
| } | ||
|
|
||
|
|
@@ -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); | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This also fix a bug was introduced by PR #1014 / TS-4861.