21 #include <QCoreApplication>
22 #include <QMutexLocker>
25 #define MAX_CONNECT_ATTEMPTS 5
27 #define CONNECT_RETRY_DELAY 2*1000
56 tc::error(
"Bug: Tried to call ControlConnection::connect() when the "
57 "control thread is already running.");
77 tc::error(
"Bug: Tried to call ControlConnection::connect() when the "
78 "control thread is already running.");
160 if (error == QAbstractSocket::ConnectionRefusedError &&
162 tc::debug(
"Control connection refused. Retrying in %1ms.")
168 tc::error(
"Vidalia was unable to connect to Tor: %1").
arg(errstr);
169 emit
connectFailed(tr(
"Vidalia was unable to connect to Tor. (%1)")
173 }
else if (error == QAbstractSocket::RemoteHostClosedError) {
176 tc::warn(
"Tor closed the control connection.");
189 tc::warn(
"Control connection attempt cancelled.");
216 case Unset: str =
"Unset";
break;
220 case Connected: str =
"Connected";
break;
221 default: str =
"unknown";
231 tc::debug(
"Control connection status changed from '%1' to '%2'")
246 if (
send(cmd, &errstr)) {
255 tc::error(
"Failed to receive control reply: %1").
arg(errstr);
263 if (!result && errmsg)
277 return err(errmsg, tr(
"Control socket is not connected."));
315 tc::error(
"Unable to read control reply: %1").
arg(errmsg);
333 Qt::DirectConnection);
335 Qt::DirectConnection);
337 Qt::DirectConnection);
338 QObject::connect(
_sock, SIGNAL(
error(QAbstractSocket::SocketError)),
339 this, SLOT(
onError(QAbstractSocket::SocketError)),
340 Qt::DirectConnection);
342 Qt::DirectConnection);
348 tc::debug(
"Starting control connection event loop.");
350 tc::debug(
"Exited control connection event loop.");
354 _sock->disconnect(
this);
368 tr(
"Control socket is not connected."));
403 const QString &errmsg)
406 _status = (success ? Success : Failed);