Changeset View
Changeset View
Standalone View
Standalone View
src/torcontrol.cpp
Show First 20 Lines • Show All 91 Lines • ▼ Show 20 Lines | public: | ||||
* Return true on success. | * Return true on success. | ||||
*/ | */ | ||||
bool Connect(const std::string &target, const ConnectionCB &connected, | bool Connect(const std::string &target, const ConnectionCB &connected, | ||||
const ConnectionCB &disconnected); | const ConnectionCB &disconnected); | ||||
/** | /** | ||||
* Disconnect from Tor control port. | * Disconnect from Tor control port. | ||||
*/ | */ | ||||
bool Disconnect(); | void Disconnect(); | ||||
/** | /** | ||||
* Send a command, register a handler for the reply. | * Send a command, register a handler for the reply. | ||||
* A trailing CRLF is automatically added. | * A trailing CRLF is automatically added. | ||||
* Return true on success. | * Return true on success. | ||||
*/ | */ | ||||
bool Command(const std::string &cmd, const ReplyHandlerCB &reply_handler); | bool Command(const std::string &cmd, const ReplyHandlerCB &reply_handler); | ||||
▲ Show 20 Lines • Show All 129 Lines • ▼ Show 20 Lines | bool TorControlConnection::Connect(const std::string &target, | ||||
if (bufferevent_socket_connect(b_conn, (struct sockaddr *)&connect_to_addr, | if (bufferevent_socket_connect(b_conn, (struct sockaddr *)&connect_to_addr, | ||||
connect_to_addrlen) < 0) { | connect_to_addrlen) < 0) { | ||||
LogPrintf("tor: Error connecting to address %s\n", target); | LogPrintf("tor: Error connecting to address %s\n", target); | ||||
return false; | return false; | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
bool TorControlConnection::Disconnect() { | void TorControlConnection::Disconnect() { | ||||
if (b_conn) { | if (b_conn) { | ||||
bufferevent_free(b_conn); | bufferevent_free(b_conn); | ||||
} | } | ||||
b_conn = nullptr; | b_conn = nullptr; | ||||
return true; | |||||
} | } | ||||
bool TorControlConnection::Command(const std::string &cmd, | bool TorControlConnection::Command(const std::string &cmd, | ||||
const ReplyHandlerCB &reply_handler) { | const ReplyHandlerCB &reply_handler) { | ||||
if (!b_conn) { | if (!b_conn) { | ||||
return false; | return false; | ||||
} | } | ||||
struct evbuffer *buf = bufferevent_get_output(b_conn); | struct evbuffer *buf = bufferevent_get_output(b_conn); | ||||
▲ Show 20 Lines • Show All 643 Lines • Show Last 20 Lines |