|
| 1 | +From 66524bee738e98742c908d93c993d0a78a2d9891 Mon Sep 17 00:00:00 2001 |
| 2 | +From: myfreeer < [email protected]> |
| 3 | +Date: Sat, 18 Nov 2017 11:55:04 +0800 |
| 4 | +Subject: [PATCH 3/4] download: retry on slow speed and conection close |
| 5 | + |
| 6 | +This would provide better speed on bad network conditions |
| 7 | +--- |
| 8 | + src/DownloadCommand.cc | 2 +- |
| 9 | + src/SocketBuffer.cc | 3 ++- |
| 10 | + src/SocketCore.cc | 2 +- |
| 11 | + 3 files changed, 4 insertions(+), 3 deletions(-) |
| 12 | + |
| 13 | +diff --git a/src/DownloadCommand.cc b/src/DownloadCommand.cc |
| 14 | +index 2db41e4..f49eb80 100644 |
| 15 | +--- a/src/DownloadCommand.cc |
| 16 | ++++ b/src/DownloadCommand.cc |
| 17 | +@@ -306,7 +306,7 @@ void DownloadCommand::checkLowestDownloadSpeed() const |
| 18 | + startupIdleTime_) { |
| 19 | + int nowSpeed = peerStat_->calculateDownloadSpeed(); |
| 20 | + if (nowSpeed <= lowestDownloadSpeedLimit_) { |
| 21 | +- throw DL_ABORT_EX2(fmt(EX_TOO_SLOW_DOWNLOAD_SPEED, nowSpeed, |
| 22 | ++ throw DL_RETRY_EX2(fmt(EX_TOO_SLOW_DOWNLOAD_SPEED, nowSpeed, |
| 23 | + lowestDownloadSpeedLimit_, |
| 24 | + getRequest()->getHost().c_str()), |
| 25 | + error_code::TOO_SLOW_DOWNLOAD_SPEED); |
| 26 | +diff --git a/src/SocketBuffer.cc b/src/SocketBuffer.cc |
| 27 | +index 62862ff..1906173 100644 |
| 28 | +--- a/src/SocketBuffer.cc |
| 29 | ++++ b/src/SocketBuffer.cc |
| 30 | +@@ -39,6 +39,7 @@ |
| 31 | + |
| 32 | + #include "SocketCore.h" |
| 33 | + #include "DlAbortEx.h" |
| 34 | ++#include "DlRetryEx.h" |
| 35 | + #include "message.h" |
| 36 | + #include "fmt.h" |
| 37 | + #include "LogFactory.h" |
| 38 | +@@ -158,7 +159,7 @@ ssize_t SocketBuffer::send() |
| 39 | + } |
| 40 | + ssize_t slen = socket_->writeVector(iov, num); |
| 41 | + if (slen == 0 && !socket_->wantRead() && !socket_->wantWrite()) { |
| 42 | +- throw DL_ABORT_EX(fmt(EX_SOCKET_SEND, "Connection closed.")); |
| 43 | ++ throw DL_RETRY_EX(fmt(EX_SOCKET_SEND, "Connection closed.")); |
| 44 | + } |
| 45 | + // A2_LOG_NOTICE(fmt("num=%zu, amount=%d, bufq.size()=%zu, SEND=%d", |
| 46 | + // num, amount, bufq_.size(), slen)); |
| 47 | +diff --git a/src/SocketCore.cc b/src/SocketCore.cc |
| 48 | +index 77dc30c..537375a 100644 |
| 49 | +--- a/src/SocketCore.cc |
| 50 | ++++ b/src/SocketCore.cc |
| 51 | +@@ -1009,7 +1009,7 @@ bool SocketCore::tlsHandshake(TLSContext* tlsctx, const std::string& hostname) |
| 52 | + |
| 53 | + if (rv == TLS_ERR_ERROR) { |
| 54 | + // Damn those error. |
| 55 | +- throw DL_ABORT_EX(fmt("SSL/TLS handshake failure: %s", |
| 56 | ++ throw DL_RETRY_EX(fmt("SSL/TLS handshake failure: %s", |
| 57 | + handshakeError.empty() |
| 58 | + ? tlsSession_->getLastErrorString().c_str() |
| 59 | + : handshakeError.c_str())); |
| 60 | +-- |
| 61 | +2.17.1 |
| 62 | + |
0 commit comments