greatsharp commented on code in PR #3077:
URL: https://github.com/apache/kvrocks/pull/3077#discussion_r2247129967
##########
src/common/io_util.cc:
##########
@@ -310,7 +310,22 @@ Status SockSetBlocking(int fd, int blocking) {
StatusOr<std::string> SockReadLine(int fd) {
UniqueEvbuf evbuf;
- if (evbuffer_read(evbuf.get(), fd, -1) <= 0) {
+ while (true) {
Review Comment:
How about add a new function like below?
`
StatusOr<std::string> SockReadLineWithRetry(int fd, int retry_times, int
retry_interval_ms) {
if (retry_times <= 0 || retry_interval_ms <= 0) {
return SockReadLine(fd);
}
UniqueEvbuf evbuf;
while (--retry_times > 0) {
int ret = evbuffer_read(evbuf.get(), fd, -1);
if (ret > 0) {
break;
}
if (ret == 0) {
return Status::FromErrno("read response err: connection closed");
}
if (errno == EAGAIN || errno == EWOULDBLOCK) {
// Resource temporarily unavailable, sleep for a while
std::this_thread::sleep_for(std::chrono::milliseconds(retry_interval_ms));
continue;
}
return Status::FromErrno("read response err");
}
UniqueEvbufReadln line(evbuf.get(), EVBUFFER_EOL_CRLF_STRICT);
if (!line) {
return Status::FromErrno("read response err(empty)");
}
return std::string(line.get(), line.length);
}
`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]