Skip to content
This repository has been archived by the owner on Dec 10, 2019. It is now read-only.

Commit

Permalink
Optimise the memory use
Browse files Browse the repository at this point in the history
  • Loading branch information
librehat committed Feb 3, 2018
1 parent 2c34361 commit fd724ad
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
23 changes: 19 additions & 4 deletions lib/network/tcprelay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,15 @@ void TcpRelay::onRemoteTcpSocketError()

void TcpRelay::onLocalTcpSocketReadyRead()
{
const QByteArray _data = local->readAll();
std::string data(_data.data(), _data.size());
std::string data;
data.resize(RemoteRecvSize);
int64_t readSize = local->read(&data[0], data.size());
if (readSize == -1) {
qCritical("Attempted to read from closed local socket.");
close();
return;
}
data.resize(readSize);

if (data.empty()) {
qCritical("Local received empty data.");
Expand Down Expand Up @@ -256,8 +263,16 @@ void TcpRelay::onLocalTcpSocketReadyRead()

void TcpRelay::onRemoteTcpSocketReadyRead()
{
QByteArray _buf = remote->readAll();
std::string buf(_buf.data(), _buf.size());
std::string buf;
buf.resize(RemoteRecvSize);
int64_t readSize = remote->read(&buf[0], buf.size());
if (readSize == -1) {
qCritical("Attempted to read from closed remote socket.");
close();
return;
}
buf.resize(readSize);

if (buf.empty()) {
qWarning("Remote received empty data.");
close();
Expand Down
5 changes: 2 additions & 3 deletions lib/types/address.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,10 @@ uint16_t Address::getPort() const
return data.second;
}

void Address::lookUp(const Address::LookUpCallback& cb)
void Address::lookUp(Address::LookUpCallback cb)
{
if (isIPValid()) {
cb(true);
return;
return cb(true);
}
std::shared_ptr<QDnsLookup> dns(new QDnsLookup(QDnsLookup::Type::ANY, QString::fromStdString(data.first)));
QObject::connect(dns.get(), &QDnsLookup::finished,
Expand Down
2 changes: 1 addition & 1 deletion lib/types/address.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class QSS_EXPORT Address
* Looks up the network address if the address is a domain name.
* The callback is invoked whenever the operation is finished.
*/
void lookUp(const LookUpCallback&);
void lookUp(LookUpCallback);

/**
* @brief blockingLookUp
Expand Down

0 comments on commit fd724ad

Please sign in to comment.