optimized
This commit is contained in:
@@ -168,7 +168,8 @@ void Connection::run() {
|
|||||||
|
|
||||||
// wait for result
|
// wait for result
|
||||||
logDebug(lf_network, "[%05d] wait for result", getID());
|
logDebug(lf_network, "[%05d] wait for result", getID());
|
||||||
string result = message.getResult();
|
string result;
|
||||||
|
message.getResult(&result);
|
||||||
|
|
||||||
if (!m_socket->isValid()) {
|
if (!m_socket->isValid()) {
|
||||||
break;
|
break;
|
||||||
|
|||||||
+13
-11
@@ -46,7 +46,7 @@ class NetMessage {
|
|||||||
* Constructor.
|
* Constructor.
|
||||||
* @param isHttp whether this is a HTTP message.
|
* @param isHttp whether this is a HTTP message.
|
||||||
*/
|
*/
|
||||||
explicit NetMessage(const bool isHttp)
|
explicit NetMessage(bool isHttp)
|
||||||
: m_isHttp(isHttp), m_resultSet(false), m_disconnect(false), m_listening(false), m_listenSince(0) {
|
: m_isHttp(isHttp), m_resultSet(false), m_disconnect(false), m_listening(false), m_listenSince(0) {
|
||||||
pthread_mutex_init(&m_mutex, NULL);
|
pthread_mutex_init(&m_mutex, NULL);
|
||||||
pthread_cond_init(&m_cond, NULL);
|
pthread_cond_init(&m_cond, NULL);
|
||||||
@@ -88,19 +88,19 @@ class NetMessage {
|
|||||||
* Return the request string.
|
* Return the request string.
|
||||||
* @return the request string.
|
* @return the request string.
|
||||||
*/
|
*/
|
||||||
string getRequest() const { return m_request; }
|
const string& getRequest() const { return m_request; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the current user name.
|
* Return the current user name.
|
||||||
* @return the current user name.
|
* @return the current user name.
|
||||||
*/
|
*/
|
||||||
string getUser() const { return m_user; }
|
const string& getUser() const { return m_user; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wait for the result being set and return the result string.
|
* Wait for the result being set and return the result string.
|
||||||
* @return the result string.
|
* @param result the variable in which to store the result string.
|
||||||
*/
|
*/
|
||||||
string getResult() {
|
void getResult(string* result) {
|
||||||
pthread_mutex_lock(&m_mutex);
|
pthread_mutex_lock(&m_mutex);
|
||||||
|
|
||||||
while (!m_resultSet) {
|
while (!m_resultSet) {
|
||||||
@@ -110,12 +110,10 @@ class NetMessage {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
m_request.clear();
|
m_request.clear();
|
||||||
string result = m_result;
|
*result = m_result;
|
||||||
m_result.clear();
|
m_result.clear();
|
||||||
m_resultSet = false;
|
m_resultSet = false;
|
||||||
pthread_mutex_unlock(&m_mutex);
|
pthread_mutex_unlock(&m_mutex);
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -126,8 +124,7 @@ class NetMessage {
|
|||||||
* @param listenUntil the end time to which to updates were added (exclusive).
|
* @param listenUntil the end time to which to updates were added (exclusive).
|
||||||
* @param disconnect true when the client shall be disconnected.
|
* @param disconnect true when the client shall be disconnected.
|
||||||
*/
|
*/
|
||||||
void setResult(const string result, const string user, const bool listening, const time_t listenUntil,
|
void setResult(const string& result, const string& user, bool listening, time_t listenUntil, bool disconnect) {
|
||||||
const bool disconnect) {
|
|
||||||
pthread_mutex_lock(&m_mutex);
|
pthread_mutex_lock(&m_mutex);
|
||||||
m_result = result;
|
m_result = result;
|
||||||
m_user = user;
|
m_user = user;
|
||||||
@@ -144,7 +141,12 @@ class NetMessage {
|
|||||||
* @param listenSince set to the start time from which to add updates (inclusive).
|
* @param listenSince set to the start time from which to add updates (inclusive).
|
||||||
* @return whether the client is in listening mode.
|
* @return whether the client is in listening mode.
|
||||||
*/
|
*/
|
||||||
bool isListening(time_t* listenSince=NULL) { if (listenSince) { *listenSince = m_listenSince; } return m_listening; }
|
bool isListening(time_t* listenSince = NULL) {
|
||||||
|
if (listenSince) {
|
||||||
|
*listenSince = m_listenSince;
|
||||||
|
}
|
||||||
|
return m_listening;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return whether the client shall be disconnected.
|
* Return whether the client shall be disconnected.
|
||||||
|
|||||||
Reference in New Issue
Block a user