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