MCPcopy Create free account
hub / github.com/aria2/aria2 / execute

Method execute

src/BackupIPv4ConnectCommand.cc:78–146  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

76}
77
78bool BackupIPv4ConnectCommand::execute()
79{
80 bool retval = false;
81 if (requestGroup_->downloadFinished() || requestGroup_->isHaltRequested()) {
82 retval = true;
83 }
84 else if (info_->cancel) {
85 A2_LOG_INFO(
86 fmt("CUID#%" PRId64 " - Backup connection canceled", getCuid()));
87 retval = true;
88 }
89 else if (socket_) {
90 if (writeEventEnabled()) {
91 try {
92 std::string error = socket_->getSocketError();
93 if (error.empty()) {
94 A2_LOG_INFO(fmt("CUID#%" PRId64 " - Backup connection to %s "
95 "established",
96 getCuid(), ipaddr_.c_str()));
97 info_->ipaddr = ipaddr_;
98 e_->deleteSocketForWriteCheck(socket_, this);
99 info_->socket.swap(socket_);
100 mainCommand_->setStatus(STATUS_ONESHOT_REALTIME);
101 e_->setNoWait(true);
102 retval = true;
103 }
104 else {
105 A2_LOG_INFO(fmt("CUID#%" PRId64 " - Backup connection failed: %s",
106 getCuid(), error.c_str()));
107 retval = true;
108 }
109 }
110 catch (RecoverableException& e) {
111 A2_LOG_INFO_EX(
112 fmt("CUID#%" PRId64 " - Backup connection failed", getCuid()), e);
113 retval = true;
114 }
115 }
116 }
117 else if (!socket_) {
118 // TODO Although we check 300ms initial timeout as described in
119 // RFC 6555, the interval will be much longer and around 1 second
120 // due to the refresh interval mechanism in DownloadEngine.
121 if (startTime_.difference(global::wallclock()) >=
122 std::chrono::milliseconds(300)) {
123 socket_ = std::make_shared<SocketCore>();
124 try {
125 socket_->establishConnection(ipaddr_, port_);
126 e_->addSocketForWriteCheck(socket_, this);
127 timeoutCheck_ = global::wallclock();
128 }
129 catch (RecoverableException& e) {
130 A2_LOG_INFO_EX(
131 fmt("CUID#%" PRId64 " - Backup connection failed", getCuid()), e);
132 socket_.reset();
133 retval = true;
134 }
135 }

Callers

nothing calls this directly

Calls 14

fmtFunction · 0.85
getSocketErrorMethod · 0.80
setNoWaitMethod · 0.80
establishConnectionMethod · 0.80
addCommandMethod · 0.80
downloadFinishedMethod · 0.45
isHaltRequestedMethod · 0.45
emptyMethod · 0.45
swapMethod · 0.45
setStatusMethod · 0.45

Tested by

no test coverage detected