SVNetwork: Avoid unneeded new / delete operations

The class variable mutex_send_ does not require an indirection
by using a pointer.

Signed-off-by: Stefan Weil <sw@weilnetz.de>
This commit is contained in:
Stefan Weil 2017-04-30 15:28:09 +02:00
parent 83588bc7a1
commit 6d19e7c3c0
2 changed files with 5 additions and 7 deletions

View File

@ -208,19 +208,19 @@ void SVSemaphore::Wait() {
// Place a message in the message buffer (and flush it).
void SVNetwork::Send(const char* msg) {
mutex_send_->Lock();
mutex_send_.Lock();
msg_buffer_out_.append(msg);
mutex_send_->Unlock();
mutex_send_.Unlock();
}
// Send the whole buffer.
void SVNetwork::Flush() {
mutex_send_->Lock();
mutex_send_.Lock();
while (!msg_buffer_out_.empty()) {
int i = send(stream_, msg_buffer_out_.c_str(), msg_buffer_out_.length(), 0);
msg_buffer_out_.erase(0, i);
}
mutex_send_->Unlock();
mutex_send_.Unlock();
}
// Receive a message from the server.
@ -387,7 +387,6 @@ static int GetAddrInfo(const char* hostname, int port,
// Set up a connection to a ScrollView on hostname:port.
SVNetwork::SVNetwork(const char* hostname, int port) {
mutex_send_ = new SVMutex();
msg_buffer_in_ = new char[kMaxMsgSize + 1];
msg_buffer_in_[0] = '\0';
@ -448,7 +447,6 @@ SVNetwork::SVNetwork(const char* hostname, int port) {
SVNetwork::~SVNetwork() {
delete[] msg_buffer_in_;
delete mutex_send_;
}
#endif // GRAPHICS_DISABLED

View File

@ -141,7 +141,7 @@ class SVNetwork {
private:
/// The mutex for access to Send() and Flush().
SVMutex* mutex_send_;
SVMutex mutex_send_;
/// The actual stream_ to the server.
int stream_;
/// Stores the last received message-chunk from the server.