summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2011-09-28 17:42:54 (GMT)
committerRemko Tronçon <git@el-tramo.be>2011-09-28 17:43:38 (GMT)
commitbab047c1bef2936124db1346863a902e1064af12 (patch)
treec59de84a76581bd07713eb0591121e6a4aa04e7b /Swiften/FileTransfer
parent7b8860c794419b63f827c9b87fbc469a1bcd58ef (diff)
downloadswift-contrib-bab047c1bef2936124db1346863a902e1064af12.zip
swift-contrib-bab047c1bef2936124db1346863a902e1064af12.tar.bz2
Pass read data from connection via shared_ptr.
This should avoid unnecessary copying of the received data while being processed by the event loop.
Diffstat (limited to 'Swiften/FileTransfer')
-rw-r--r--Swiften/FileTransfer/SOCKS5BytestreamClientSession.cpp10
-rw-r--r--Swiften/FileTransfer/SOCKS5BytestreamClientSession.h2
-rw-r--r--Swiften/FileTransfer/SOCKS5BytestreamServerSession.cpp8
-rw-r--r--Swiften/FileTransfer/SOCKS5BytestreamServerSession.h2
-rw-r--r--Swiften/FileTransfer/UnitTest/SOCKS5BytestreamClientSessionTest.cpp30
5 files changed, 26 insertions, 26 deletions
diff --git a/Swiften/FileTransfer/SOCKS5BytestreamClientSession.cpp b/Swiften/FileTransfer/SOCKS5BytestreamClientSession.cpp
index a18b998..db3d83f 100644
--- a/Swiften/FileTransfer/SOCKS5BytestreamClientSession.cpp
+++ b/Swiften/FileTransfer/SOCKS5BytestreamClientSession.cpp
@@ -209,15 +209,15 @@ void SOCKS5BytestreamClientSession::handleConnectFinished(bool error) {
}
}
-void SOCKS5BytestreamClientSession::handleDataRead(const SafeByteArray& data) {
- SWIFT_LOG(debug) << "state: " << state << " data.size() = " << data.size() << std::endl;
+void SOCKS5BytestreamClientSession::handleDataRead(boost::shared_ptr<SafeByteArray> data) {
+ SWIFT_LOG(debug) << "state: " << state << " data.size() = " << data->size() << std::endl;
if (state != Reading) {
- append(unprocessedData, data);
+ append(unprocessedData, *data);
process();
}
else {
- writeBytestream->write(createByteArray(vecptr(data), data.size()));
- onBytesReceived(data.size());
+ writeBytestream->write(createByteArray(vecptr(*data), data->size()));
+ onBytesReceived(data->size());
}
}
diff --git a/Swiften/FileTransfer/SOCKS5BytestreamClientSession.h b/Swiften/FileTransfer/SOCKS5BytestreamClientSession.h
index 894e977..ea45955 100644
--- a/Swiften/FileTransfer/SOCKS5BytestreamClientSession.h
+++ b/Swiften/FileTransfer/SOCKS5BytestreamClientSession.h
@@ -66,7 +66,7 @@ private:
void authenticate();
void handleConnectFinished(bool error);
- void handleDataRead(const SafeByteArray&);
+ void handleDataRead(boost::shared_ptr<SafeByteArray>);
void handleDisconnected(const boost::optional<Connection::Error>&);
void handleWeFailedTimeout();
diff --git a/Swiften/FileTransfer/SOCKS5BytestreamServerSession.cpp b/Swiften/FileTransfer/SOCKS5BytestreamServerSession.cpp
index fa7e054..def9e33 100644
--- a/Swiften/FileTransfer/SOCKS5BytestreamServerSession.cpp
+++ b/Swiften/FileTransfer/SOCKS5BytestreamServerSession.cpp
@@ -65,13 +65,13 @@ HostAddressPort SOCKS5BytestreamServerSession::getAddressPort() const {
return connection->getLocalAddress();
}
-void SOCKS5BytestreamServerSession::handleDataRead(const SafeByteArray& data) {
+void SOCKS5BytestreamServerSession::handleDataRead(boost::shared_ptr<SafeByteArray> data) {
if (state != ReadingData) {
- append(unprocessedData, data);
+ append(unprocessedData, *data);
process();
} else {
- writeBytestream->write(createByteArray(vecptr(data), data.size()));
- onBytesReceived(data.size());
+ writeBytestream->write(createByteArray(vecptr(*data), data->size()));
+ onBytesReceived(data->size());
}
}
diff --git a/Swiften/FileTransfer/SOCKS5BytestreamServerSession.h b/Swiften/FileTransfer/SOCKS5BytestreamServerSession.h
index 3e1018f..4557a36 100644
--- a/Swiften/FileTransfer/SOCKS5BytestreamServerSession.h
+++ b/Swiften/FileTransfer/SOCKS5BytestreamServerSession.h
@@ -52,7 +52,7 @@ namespace Swift {
private:
void finish(bool error);
void process();
- void handleDataRead(const SafeByteArray&);
+ void handleDataRead(boost::shared_ptr<SafeByteArray>);
void handleDisconnected(const boost::optional<Connection::Error>&);
void sendData();
diff --git a/Swiften/FileTransfer/UnitTest/SOCKS5BytestreamClientSessionTest.cpp b/Swiften/FileTransfer/UnitTest/SOCKS5BytestreamClientSessionTest.cpp
index 75b9faf..527e0ca 100644
--- a/Swiften/FileTransfer/UnitTest/SOCKS5BytestreamClientSessionTest.cpp
+++ b/Swiften/FileTransfer/UnitTest/SOCKS5BytestreamClientSessionTest.cpp
@@ -164,7 +164,7 @@ public:
clientSession->startReceiving(output);
ByteArray transferData = generateRandomByteArray(1024);
- connection->onDataRead(createSafeByteArray(transferData.data(), transferData.size()));
+ connection->onDataRead(createSafeByteArrayRef(transferData.data(), transferData.size()));
CPPUNIT_ASSERT_EQUAL(transferData, output->getData());
}
@@ -212,35 +212,35 @@ private:
// Server responses
void serverRespondHelloOK() {
- connection->onDataRead(createSafeByteArray("\x05\00", 2));
+ connection->onDataRead(createSafeByteArrayRef("\x05\00", 2));
}
void serverRespondHelloAuthFail() {
- connection->onDataRead(createSafeByteArray("\x05\xFF", 2));
+ connection->onDataRead(createSafeByteArrayRef("\x05\xFF", 2));
}
void serverRespondRequestOK() {
- SafeByteArray dataToSend = createSafeByteArray("\x05\x00\x00\x03", 4);
- append(dataToSend, createSafeByteArray(destination.size()));
- append(dataToSend, createSafeByteArray(destination));
- append(dataToSend, createSafeByteArray("\x00", 1));
+ boost::shared_ptr<SafeByteArray> dataToSend = createSafeByteArrayRef("\x05\x00\x00\x03", 4);
+ append(*dataToSend, createSafeByteArray(destination.size()));
+ append(*dataToSend, createSafeByteArray(destination));
+ append(*dataToSend, createSafeByteArray("\x00", 1));
connection->onDataRead(dataToSend);
}
void serverRespondRequestFail() {
- SafeByteArray correctData = createSafeByteArray("\x05\x00\x00\x03", 4);
- append(correctData, createSafeByteArray(destination.size()));
- append(correctData, createSafeByteArray(destination));
- append(correctData, createSafeByteArray("\x00", 1));
+ boost::shared_ptr<SafeByteArray> correctData = createSafeByteArrayRef("\x05\x00\x00\x03", 4);
+ append(*correctData, createSafeByteArray(destination.size()));
+ append(*correctData, createSafeByteArray(destination));
+ append(*correctData, createSafeByteArray("\x00", 1));
- SafeByteArray dataToSend;
+ boost::shared_ptr<SafeByteArray> dataToSend;
//ByteArray failingData = Hexify::unhexify("8417947d1d305c72c11520ea7d2c6e787396705e72c312c6ccc3f66613d7cae1b91b7ab48e8b59a17d559c15fb51");
//append(dataToSend, failingData);
//SWIFT_LOG(debug) << "hexed: " << Hexify::hexify(failingData) << std::endl;
do {
- ByteArray rndArray = generateRandomByteArray(correctData.size());
- dataToSend = createSafeByteArray(rndArray.data(), rndArray.size());
- } while (dataToSend == correctData);
+ ByteArray rndArray = generateRandomByteArray(correctData->size());
+ dataToSend = createSafeByteArrayRef(rndArray.data(), rndArray.size());
+ } while (*dataToSend == *correctData);
connection->onDataRead(dataToSend);
}