| 177 | } |
| 178 | |
| 179 | bool AbstractCommand::execute() |
| 180 | { |
| 181 | A2_LOG_DEBUG(fmt("CUID#%" PRId64 |
| 182 | " - socket: read:%d, write:%d, hup:%d, err:%d", |
| 183 | getCuid(), readEventEnabled(), writeEventEnabled(), |
| 184 | hupEventEnabled(), errorEventEnabled())); |
| 185 | try { |
| 186 | if (requestGroup_->downloadFinished() || requestGroup_->isHaltRequested()) { |
| 187 | return true; |
| 188 | } |
| 189 | |
| 190 | if (req_ && req_->removalRequested()) { |
| 191 | A2_LOG_DEBUG(fmt("CUID#%" PRId64 |
| 192 | " - Discard original URI=%s because it is" |
| 193 | " requested.", |
| 194 | getCuid(), req_->getUri().c_str())); |
| 195 | return prepareForRetry(0); |
| 196 | } |
| 197 | |
| 198 | auto sm = getSegmentMan(); |
| 199 | |
| 200 | if (getPieceStorage()) { |
| 201 | segments_.clear(); |
| 202 | sm->getInFlightSegment(segments_, getCuid()); |
| 203 | |
| 204 | if (req_ && segments_.empty()) { |
| 205 | // This command previously has assigned segments, but it is |
| 206 | // canceled. So discard current request chain. Plus, if no |
| 207 | // segment is available when http pipelining is used. |
| 208 | A2_LOG_DEBUG(fmt("CUID#%" PRId64 |
| 209 | " - It seems previously assigned segments" |
| 210 | " are canceled. Restart.", |
| 211 | getCuid())); |
| 212 | // Request::isPipeliningEnabled() == true means aria2 |
| 213 | // accessed the remote server and discovered that the server |
| 214 | // supports pipelining. |
| 215 | if (req_ && req_->isPipeliningEnabled()) { |
| 216 | e_->poolSocket(req_, createProxyRequest(), socket_); |
| 217 | } |
| 218 | return prepareForRetry(0); |
| 219 | } |
| 220 | |
| 221 | // TODO it is not needed to check other PeerStats every time. |
| 222 | // Find faster Request when no segment split is allowed. |
| 223 | if (req_ && fileEntry_->countPooledRequest() > 0 && |
| 224 | requestGroup_->getPendingLength() < calculateMinSplitSize() * 2) { |
| 225 | auto fasterRequest = fileEntry_->findFasterRequest(req_); |
| 226 | if (fasterRequest) { |
| 227 | useFasterRequest(fasterRequest); |
| 228 | return true; |
| 229 | } |
| 230 | } |
| 231 | // Don't use this feature if PREF_MAX_{OVERALL_}DOWNLOAD_LIMIT |
| 232 | // is used or total length is unknown. |
| 233 | if (req_ && fileEntry_->getLength() > 0 && |
| 234 | e_->getRequestGroupMan()->getMaxOverallDownloadSpeedLimit() == 0 && |
| 235 | requestGroup_->getMaxDownloadSpeedLimit() == 0 && |
| 236 | serverStatTimer_.difference(global::wallclock()) >= 10_s) { |
nothing calls this directly
no test coverage detected