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);
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);
#define CONNECT_RETRY_DELAY
#define MAX_CONNECT_ATTEMPTS
stop errmsg connect(const QHostAddress &address, quint16 port)
enum ControlConnection::ReceiveWaiter::ReceiveStatus _status
bool getResult(ControlReply *reply, QString *errmsg=0)
void setResult(bool success, const ControlReply &reply, const QString &errmsg=QString())
void onError(QAbstractSocket::SocketError error)
ControlConnection(ControlMethod::Method method, TorEvents *events=0)
QQueue< ReceiveWaiter * > _recvQueue
void setStatus(Status status)
void connectFailed(QString errmsg)
QString statusString(Status status)
bool send(const ControlCommand &cmd, ControlReply &reply, QString *errmsg=0)
ControlMethod::Method _method
SendCommandEvent::SendWaiter * _sendWaiter
QString getStatus() const
static QString toString(const QAbstractSocket::SocketError error)
void disconnectFromHost()
void connectToHost(const QHostAddress &address, quint16 port)
bool readReply(ControlReply &reply, QString *errmsg=0)
void disconnectFromServer()
void connectToServer(const QString &name)
bool getResult(QString *errmsg=0)
void setResult(bool success, const QString &errmsg=QString())
void handleEvent(const ControlReply &reply)
DebugMessage arg(const QString &a)
DebugMessage warn(const QString &fmt)
DebugMessage error(const QString &fmt)
DebugMessage debug(const QString &fmt)
bool err(QString *str, const QString &errmsg)