[network/libktorrent] src: ABI/API break: Port socket send functions to QByteArrayView
Jack Hill <[email protected]>
| Newsgroups | gmane.comp.kde.cvs |
|---|---|
| Message-ID | <[email protected]> |
Git commit 97d116083f9f37e4dead92a4d6aa94cd4c8408fe by Jack Hill.
Committed on 18/07/2026 at 13:45.
Pushed by jackh into branch 'master'.
ABI/API break: Port socket send functions to QByteArrayView
No downstream changes required.
M +1 -1 src/download/packet.cpp
M +9 -7 src/mse/encryptedauthenticate.cpp
M +9 -9 src/mse/encryptedpacketsocket.cpp
M +3 -2 src/mse/encryptedpacketsocket.h
M +6 -4 src/mse/encryptedserverauthenticate.cpp
M +3 -3 src/net/socket.cpp
M +1 -1 src/net/socket.h
M +3 -1 src/net/socketdevice.h
M +7 -7 src/net/socks.cpp
M +1 -1 src/net/streamsocket.cpp
M +5 -4 src/net/tests/polltest.cpp
M +6 -3 src/peer/authenticatebase.cpp
M +2 -2 src/peer/peer.cpp
M +1 -2 src/peer/peer.h
M +2 -2 src/utp/connection.cpp
M +2 -1 src/utp/connection.h
M +1 -1 src/utp/tests/congestiontest.cpp
M +1 -1 src/utp/tests/fintest.cpp
M +1 -1 src/utp/tests/packetlosstest.cpp
M +11 -9 src/utp/tests/sendtest.cpp
M +1 -1 src/utp/tests/sockettest.cpp
M +1 -1 src/utp/tests/transmittest.cpp
M +1 -1 src/utp/tests/utppolltest.cpp
M +2 -2 src/utp/utpsocket.cpp
M +1 -1 src/utp/utpsocket.h
https://invent.kde.org/network/libktorrent/-/commit/97d116083f9f37e4dead92a4d6aa94cd4c8408fe
diff --git a/src/download/packet.cpp b/src/download/packet.cpp
index dc78b20a..f663291b 100644
--- a/src/download/packet.cpp
+++ b/src/download/packet.cpp
@@ -135,7 +135,7 @@ int Packet::send(net::SocketDevice *sock, Uint32 max_to_send)
if (bw > max_to_send && max_to_send > 0) {
bw = max_to_send;
}
- const int ret = sock->send(getData() + written, bw);
+ const int ret = sock->send(QByteArrayView{getData() + written, bw});
if (ret > 0) {
written += ret;
}
diff --git a/src/mse/encryptedauthenticate.cpp b/src/mse/encryptedauthenticate.cpp
index d90b0323..77b7583e 100644
--- a/src/mse/encryptedauthenticate.cpp
+++ b/src/mse/encryptedauthenticate.cpp
@@ -5,8 +5,10 @@
*/
#include "encryptedauthenticate.h"
-#include <QRandomGenerator>
#include <algorithm>
+#include <array>
+
+#include <QRandomGenerator>
#include "encryptedpacketsocket.h"
#include "functions.h"
@@ -46,9 +48,9 @@ EncryptedAuthenticate::~EncryptedAuthenticate()
void EncryptedAuthenticate::connected()
{
// we are connected so send ya and some padding
- Uint8 tmp[608];
- ya.toBuffer(tmp, 96);
- sock->sendData(tmp, 96 + QRandomGenerator::global()->bounded(512));
+ std::array<Uint8, 96 + 512> tmp;
+ ya.toBuffer(tmp.data(), 96);
+ sock->sendData(QByteArrayView{tmp}.chopped(QRandomGenerator::global()->bounded(512)));
state = SENT_YA;
}
@@ -84,7 +86,7 @@ void EncryptedAuthenticate::handleYB()
memcpy(tmp_buf, "req1", 4);
s.toBuffer(tmp_buf + 4, 96);
h1 = SHA1Hash::generate(tmp_buf, 100);
- sock->sendData(h1.getData(), 20);
+ sock->sendData(h1);
// generate second and third hash and xor them
memcpy(tmp_buf, "req2", 4);
@@ -94,7 +96,7 @@ void EncryptedAuthenticate::handleYB()
memcpy(tmp_buf, "req3", 4);
s.toBuffer(tmp_buf + 4, 96);
h2 = SHA1Hash::generate(tmp_buf, 100);
- sock->sendData((h1 ^ h2).getData(), 20);
+ sock->sendData(h1 ^ h2);
// now we enter encrypted mode the keys are :
// HASH('keyA', S, SKEY) for the encryption key
@@ -115,7 +117,7 @@ void EncryptedAuthenticate::handleYB()
WriteUint16(tmp_buf, 14, 68); // length of IA, which will be the bittorrent handshake
// send IA which is the handshake
makeHandshake(tmp_buf + 16, info_hash, our_peer_id);
- sock->sendData(our_rc4->encrypt(tmp_buf, 84), 84);
+ sock->sendData(QByteArrayView{our_rc4->encrypt(tmp_buf, 84), 84});
// search for the encrypted VC in the data
findVC();
diff --git a/src/mse/encryptedpacketsocket.cpp b/src/mse/encryptedpacketsocket.cpp
index dbc85e60..69164fe2 100644
--- a/src/mse/encryptedpacketsocket.cpp
+++ b/src/mse/encryptedpacketsocket.cpp
@@ -94,27 +94,27 @@ void EncryptedPacketSocket::stopMonitoring()
rdr = nullptr;
}
-Uint32 EncryptedPacketSocket::sendData(const Uint8 *data, Uint32 len)
+Uint32 EncryptedPacketSocket::sendData(QByteArrayView data)
{
if (enc) {
// we need to make sure all data is sent because of the encryption
Uint32 ds = 0;
- const Uint8 *ed = enc->encrypt(data, len);
- while (sock->ok() && ds < len) {
- const Uint32 ret = sock->send(ed + ds, len - ds);
+ const Uint8 *ed = enc->encrypt(reinterpret_cast<const Uint8 *>(data.data()), data.size());
+ while (sock->ok() && ds < data.size()) {
+ const Uint32 ret = sock->send(QByteArrayView{ed, data.size()}.sliced(ds));
ds += ret;
if (ret == 0) {
Out(SYS_CON | LOG_DEBUG) << "ret = 0" << endl;
}
}
- if (ds != len) {
- Out(SYS_CON | LOG_DEBUG) << "ds != len" << endl;
+ if (ds != data.size()) {
+ Out(SYS_CON | LOG_DEBUG) << "ds != data.size()" << endl;
}
return ds;
} else {
- const Uint32 ret = sock->send(data, len);
- if (ret != len) {
- Out(SYS_CON | LOG_DEBUG) << "ret != len" << endl;
+ const Uint32 ret = sock->send(data);
+ if (ret != data.size()) {
+ Out(SYS_CON | LOG_DEBUG) << "ret != data.size()" << endl;
}
return ret;
}
diff --git a/src/mse/encryptedpacketsocket.h b/src/mse/encryptedpacketsocket.h
index 2c3e1c45..5208df6a 100644
--- a/src/mse/encryptedpacketsocket.h
+++ b/src/mse/encryptedpacketsocket.h
@@ -6,6 +6,8 @@
#ifndef MSESTREAMSOCKET_H
#define MSESTREAMSOCKET_H
+#include <QByteArrayView>
+
#include <ktorrent_export.h>
#include <net/packetsocket.h>
#include <util/constants.h>
@@ -40,10 +42,9 @@ public:
/*!
* Send a chunk of data. (Does not encrypt the data)
* \param data The data
- * \param len The length
* \return Number of bytes written
*/
- bt::Uint32 sendData(const bt::Uint8 *data, bt::Uint32 len);
+ bt::Uint32 sendData(QByteArrayView data);
/*!
* Reads data from the peer.
diff --git a/src/mse/encryptedserverauthenticate.cpp b/src/mse/encryptedserverauthenticate.cpp
index 40caf9d7..814f8f82 100644
--- a/src/mse/encryptedserverauthenticate.cpp
+++ b/src/mse/encryptedserverauthenticate.cpp
@@ -5,6 +5,8 @@
*/
#include "encryptedserverauthenticate.h"
+#include <array>
+
#include <QRandomGenerator>
#include "encryptedpacketsocket.h"
@@ -36,11 +38,11 @@ EncryptedServerAuthenticate::~EncryptedServerAuthenticate()
void EncryptedServerAuthenticate::sendYB()
{
- Uint8 tmp[608];
- yb.toBuffer(tmp, 96);
+ std::array<Uint8, 96 + 512> tmp;
+ yb.toBuffer(tmp.data(), 96);
// DumpBigInt("Xb",xb);
// DumpBigInt("Yb",yb);
- sock->sendData(tmp, 96 + QRandomGenerator::global()->bounded(512));
+ sock->sendData(QByteArrayView{tmp}.chopped(QRandomGenerator::global()->bounded(512)));
// Out() << "Sent YB" << endl;
}
@@ -161,7 +163,7 @@ void EncryptedServerAuthenticate::processVC()
}
bt::WriteUint16(tmp, 12, 0); // no pad D
- sock->sendData(our_rc4->encrypt(tmp, 14), 14);
+ sock->sendData(QByteArrayView{our_rc4->encrypt(tmp, 14), 14});
// handle pad C
if (buf_size < req1_off + 14 + pad_C_len) {
diff --git a/src/net/socket.cpp b/src/net/socket.cpp
index e6f8e9d4..9be2f401 100644
--- a/src/net/socket.cpp
+++ b/src/net/socket.cpp
@@ -261,12 +261,12 @@ bool Socket::bind(const net::Address &addr, bool also_listen)
return true;
}
-int Socket::send(const bt::Uint8 *buf, int len)
+int Socket::send(QByteArrayView buf)
{
#ifndef Q_OS_WIN
- const int ret = ::send(m_fd, buf, len, MSG_NOSIGNAL);
+ const int ret = ::send(m_fd, buf.data(), buf.size(), MSG_NOSIGNAL);
#else
- const int ret = ::send(m_fd, (char *)buf, len, MSG_NOSIGNAL);
+ const int ret = ::send(m_fd, buf.data(), buf.size(), MSG_NOSIGNAL);
#endif
if (ret < 0) {
const int err = errno;
diff --git a/src/net/socket.h b/src/net/socket.h
index 67b85dd0..5dafdccb 100644
--- a/src/net/socket.h
+++ b/src/net/socket.h
@@ -33,7 +33,7 @@ public:
bool connectSuccessful() override;
void close() override;
[[nodiscard]] bt::Uint32 bytesAvailable() const override;
- int send(const bt::Uint8 *buf, int len) override;
+ int send(QByteArrayView buf) override;
int recv(bt::Uint8 *buf, int max_len) override;
[[nodiscard]] bool ok() const override
{
diff --git a/src/net/socketdevice.h b/src/net/socketdevice.h
index b99b916f..0d42ff85 100644
--- a/src/net/socketdevice.h
+++ b/src/net/socketdevice.h
@@ -7,6 +7,8 @@
#ifndef NET_SOCKETDEVICE_H
#define NET_SOCKETDEVICE_H
+#include <QByteArrayView>
+
#include <ktorrent_export.h>
#include <net/address.h>
#include <net/poll.h>
@@ -54,7 +56,7 @@ public:
[[nodiscard]] virtual int fd() const = 0;
[[nodiscard]] virtual bool ok() const = 0;
- virtual int send(const bt::Uint8 *buf, int len) = 0;
+ virtual int send(QByteArrayView buf) = 0;
virtual int recv(bt::Uint8 *buf, int max_len) = 0;
virtual void close() = 0;
virtual void setBlocking(bool on) = 0;
diff --git a/src/net/socks.cpp b/src/net/socks.cpp
index 765d958e..31c096b9 100644
--- a/src/net/socks.cpp
+++ b/src/net/socks.cpp
@@ -136,7 +136,7 @@ Socks::State Socks::sendAuthRequest()
req.methods[0] = socks5::AuthMethod::NONE; // No authentication
req.methods[1] = socks5::AuthMethod::USERNAME_PASSWORD; // Username and password
req.methods[2] = socks5::AuthMethod::GSSAPI; // GSSAPI
- sock->sendData((const Uint8 *)&req, req.size());
+ sock->sendData(QByteArrayView{reinterpret_cast<const Uint8 *>(&req), req.size()});
internal_state = AUTH_REQUEST_SENT;
} else {
if (dest.protocol() == QAbstractSocket::IPv6Protocol) {
@@ -154,7 +154,7 @@ Socks::State Socks::sendAuthRequest()
quint32 ip = htonl(dest.toIPv4Address());
memcpy(req.ip, &ip, 4);
strcpy(req.user_id, "KTorrent");
- sock->sendData((const Uint8 *)&req, req.size());
+ sock->sendData(QByteArrayView{reinterpret_cast<const Uint8 *>(&req), req.size()});
internal_state = CONNECT_REQUEST_SENT;
// Out(SYS_CON|LOG_DEBUG) << "SOCKSV4 send connect" << endl;
}
@@ -195,15 +195,15 @@ void Socks::sendUsernamePassword()
const QByteArray user = socks_username.toLocal8Bit();
const QByteArray pwd = socks_password.toLocal8Bit();
Uint32 off = 0;
- Uint8 buffer[3 + 2 * 256];
+ std::array<Uint8, 3 + 2 * 256> buffer;
buffer[off++] = 0x01; // version
buffer[off++] = user.size();
- memcpy(buffer + off, user.constData(), user.size());
+ memcpy(buffer.data() + off, user.constData(), user.size());
off += user.size();
buffer[off++] = pwd.size();
- memcpy(buffer + off, pwd.constData(), pwd.size());
+ memcpy(buffer.data() + off, pwd.constData(), pwd.size());
off += pwd.size();
- sock->sendData(buffer, off);
+ sock->sendData(QByteArrayView{buffer}.first(off));
internal_state = USERNAME_AND_PASSWORD_SENT;
}
@@ -247,7 +247,7 @@ void Socks::sendConnectRequest()
len += 16;
req.address_type = socks5::AddressType::ADDR_IPV6;
}
- sock->sendData((const Uint8 *)&req, len);
+ sock->sendData(QByteArrayView{reinterpret_cast<const Uint8 *>(&req), len});
internal_state = CONNECT_REQUEST_SENT;
}
diff --git a/src/net/streamsocket.cpp b/src/net/streamsocket.cpp
index 71ec6399..74fd0ee3 100644
--- a/src/net/streamsocket.cpp
+++ b/src/net/streamsocket.cpp
@@ -53,7 +53,7 @@ bt::Uint32 StreamSocket::write(bt::Uint32 max, bt::TimeStamp now)
// max 0 means unlimited transfer, try to send the entire buffer then
const int to_send = (max == 0) ? buffer.size() : qMin<int>(buffer.size(), max);
- const int ret = sock->send((const bt::Uint8 *)buffer.data(), to_send);
+ const int ret = sock->send(QByteArrayView{buffer}.first(to_send));
if (ret == to_send) {
buffer.clear();
if (listener) {
diff --git a/src/net/tests/polltest.cpp b/src/net/tests/polltest.cpp
index c6ba81f9..93af984e 100644
--- a/src/net/tests/polltest.cpp
+++ b/src/net/tests/polltest.cpp
@@ -4,6 +4,8 @@
SPDX-License-Identifier: GPL-2.0-or-later
*/
+#include <array>
+
#include <QObject>
#include <QTest>
@@ -134,16 +136,15 @@ private Q_SLOTS:
net::Socket reader(fd, reader_ip_version);
- bt::Uint8 data[20];
- memset(data, 0xFF, 20);
- QCOMPARE(writer.send(data, 20), 20);
+ constexpr std::array<bt::Uint8, 20> data = {0xFF};
+ QCOMPARE(writer.send(data), data.size());
reader.prepare(&poll, net::Poll::INPUT);
QCOMPARE_GT(poll.poll(1000), 0);
bt::Uint8 tmp[20];
QCOMPARE(reader.recv(tmp, 20), 20);
- QCOMPARE(memcmp(tmp, data, 20), 0);
+ QCOMPARE(memcmp(tmp, data.data(), 20), 0);
}
private:
diff --git a/src/peer/authenticatebase.cpp b/src/peer/authenticatebase.cpp
index 47051f35..6f89b9ba 100644
--- a/src/peer/authenticatebase.cpp
+++ b/src/peer/authenticatebase.cpp
@@ -4,6 +4,9 @@
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "authenticatebase.h"
+
+#include <array>
+
#include <dht/dhtbase.h>
#include <mse/encryptedpacketsocket.h>
#include <peer/peerid.h>
@@ -49,9 +52,9 @@ void AuthenticateBase::sendHandshake(const SHA1Hash &info_hash, const PeerID &ou
return;
}
- Uint8 hs[68];
- makeHandshake(hs, info_hash, our_peer_id);
- sock->sendData(hs, 68);
+ std::array<Uint8, 68> hs;
+ makeHandshake(hs.data(), info_hash, our_peer_id);
+ sock->sendData(hs);
}
void AuthenticateBase::makeHandshake(Uint8 *hs, const SHA1Hash &info_hash, const PeerID &our_peer_id)
diff --git a/src/peer/peer.cpp b/src/peer/peer.cpp
index 52f7286d..f10bf55e 100644
--- a/src/peer/peer.cpp
+++ b/src/peer/peer.cpp
@@ -459,13 +459,13 @@ void Peer::handleExtendedHandshake(const Uint8 *packet, Uint32 size)
}
}
-Uint32 Peer::sendData(const Uint8 *data, Uint32 len)
+Uint32 Peer::sendData(QByteArrayView data)
{
if (killed) {
return 0;
}
- const Uint32 ret = sock->sendData(data, len);
+ const Uint32 ret = sock->sendData(data);
if (!sock->ok()) {
kill();
}
diff --git a/src/peer/peer.h b/src/peer/peer.h
index 676dd348..ed7d4b7d 100644
--- a/src/peer/peer.h
+++ b/src/peer/peer.h
@@ -127,10 +127,9 @@ public:
/*!
* Send a chunk of data.
* \param data The data
- * \param len The length
* \return Number of bytes written
*/
- Uint32 sendData(const Uint8 *data, Uint32 len);
+ Uint32 sendData(QByteArrayView data);
/*!
* Reads data from the peer.
diff --git a/src/utp/connection.cpp b/src/utp/connection.cpp
index e92e1622..e360a459 100644
--- a/src/utp/connection.cpp
+++ b/src/utp/connection.cpp
@@ -398,7 +398,7 @@ void Connection::updateDelayMeasurement(const utp::Header *hdr, double window_fa
*/
}
-int Connection::send(const bt::Uint8 *data, Uint32 len)
+int Connection::send(QByteArrayView data)
{
const QMutexLocker lock(&mutex);
if (stats.state != CS_CONNECTED) {
@@ -406,7 +406,7 @@ int Connection::send(const bt::Uint8 *data, Uint32 len)
}
// first put data in the output buffer then send packets
- const bt::Uint32 ret = output_buffer.write(QByteArrayView{data, len});
+ const bt::Uint32 ret = output_buffer.write(data);
sendPackets();
stats.writeable = !output_buffer.full();
return ret;
diff --git a/src/utp/connection.h b/src/utp/connection.h
index 457a083d..aa92f696 100644
--- a/src/utp/connection.h
+++ b/src/utp/connection.h
@@ -8,6 +8,7 @@
#define UTP_CONNECTION_H
#include <QBasicTimer>
+#include <QByteArrayView>
#include <QMutex>
#include <QPair>
#include <QSharedPointer>
@@ -129,7 +130,7 @@ public:
}
//! Send some data, returns the amount of bytes sent (or -1 on error)
- int send(const bt::Uint8 *data, bt::Uint32 len);
+ int send(QByteArrayView data);
//! Read available data from local window, returns the amount of bytes read
int recv(bt::Uint8 *buf, bt::Uint32 max_len);
diff --git a/src/utp/tests/congestiontest.cpp b/src/utp/tests/congestiontest.cpp
index b9f09065..a61c1af3 100644
--- a/src/utp/tests/congestiontest.cpp
+++ b/src/utp/tests/congestiontest.cpp
@@ -74,7 +74,7 @@ public:
char test[] = TEST_DATA;
int sent = 0;
while (sent < PACKETS_TO_SEND) {
- int ret = outgoing->send((const bt::Uint8 *)test, strlen(test));
+ int ret = outgoing->send(test);
if (ret > 0) {
sent++;
}
diff --git a/src/utp/tests/fintest.cpp b/src/utp/tests/fintest.cpp
index b4f1c832..4fc0ca1e 100644
--- a/src/utp/tests/fintest.cpp
+++ b/src/utp/tests/fintest.cpp
@@ -72,7 +72,7 @@ private:
}
char test[] = "This is the fin test";
- outgoing->send((const bt::Uint8 *)test, strlen(test));
+ outgoing->send(test);
incoming->setBlocking(true);
if (incoming->waitForData()) {
bt::Uint8 tmp[100];
diff --git a/src/utp/tests/packetlosstest.cpp b/src/utp/tests/packetlosstest.cpp
index d77015c9..db1f760b 100644
--- a/src/utp/tests/packetlosstest.cpp
+++ b/src/utp/tests/packetlosstest.cpp
@@ -80,7 +80,7 @@ public:
{
int sent = 0;
while (sent < PACKETS_TO_SEND && outgoing->connectionState() != CS_CLOSED) {
- const int ret = outgoing->send((const bt::Uint8 *)TEST_DATA.constData(), TEST_DATA.size());
+ const int ret = outgoing->send(TEST_DATA);
if (ret > 0) {
sent++;
}
diff --git a/src/utp/tests/sendtest.cpp b/src/utp/tests/sendtest.cpp
index 09a58050..11926909 100644
--- a/src/utp/tests/sendtest.cpp
+++ b/src/utp/tests/sendtest.cpp
@@ -3,6 +3,9 @@
SPDX-License-Identifier: GPL-2.0-or-later
*/
+
+#include <array>
+
#include <QObject>
#include <QTest>
#include <QTimer>
@@ -83,7 +86,7 @@ private:
outgoing->setBlocking(true);
char test[] = "TEST";
- int ret = outgoing->send((const bt::Uint8 *)test, strlen(test));
+ int ret = outgoing->send(test);
QCOMPARE(ret, (int)strlen(test));
char tmp[20];
@@ -96,16 +99,15 @@ private:
void testSend2()
{
bt::Out(SYS_UTP | LOG_DEBUG) << "testSend2" << bt::endl;
- const bt::Uint8 *sdata = new bt::Uint8[1000];
- outgoing->send(sdata, 1000);
+ constexpr std::array<bt::Uint8, 1000> sdata{0xFF};
+ outgoing->send(sdata);
bt::Uint8 *rdata = new bt::Uint8[1000];
const int ret = incoming->recv(rdata, 1000);
QCOMPARE(ret, 1000);
- QCOMPARE(memcmp(sdata, rdata, ret), 0);
+ QCOMPARE(memcmp(sdata.data(), rdata, ret), 0);
delete[] rdata;
- delete[] sdata;
}
void testSend3()
@@ -113,8 +115,8 @@ private:
bt::Out(SYS_UTP | LOG_DEBUG) << "testSend3" << bt::endl;
char test[] = "TEST";
- outgoing->send((const bt::Uint8 *)test, strlen(test));
- incoming->send((const bt::Uint8 *)test, strlen(test));
+ outgoing->send(test);
+ incoming->send(test);
char tmp[20];
memset(tmp, 0, 20);
@@ -133,8 +135,8 @@ private:
bt::Out(SYS_UTP | LOG_DEBUG) << "testSend4" << bt::endl;
char test[] = "TEST";
- outgoing->send((const bt::Uint8 *)test, strlen(test));
- outgoing->send((const bt::Uint8 *)test, strlen(test));
+ outgoing->send(test);
+ outgoing->send(test);
char tmp[20];
memset(tmp, 0, 20);
diff --git a/src/utp/tests/sockettest.cpp b/src/utp/tests/sockettest.cpp
index 604941be..92a7d477 100644
--- a/src/utp/tests/sockettest.cpp
+++ b/src/utp/tests/sockettest.cpp
@@ -78,7 +78,7 @@ private:
UTPSocket *a = incoming;
UTPSocket *b = outgoing;
for (int i = 0; i < 10; i++) {
- int ret = a->send((const bt::Uint8 *)test, strlen(test));
+ int ret = a->send(test);
QCOMPARE(ret, (int)strlen(test));
char tmp[20];
diff --git a/src/utp/tests/transmittest.cpp b/src/utp/tests/transmittest.cpp
index 60b743d1..ce6e59ba 100644
--- a/src/utp/tests/transmittest.cpp
+++ b/src/utp/tests/transmittest.cpp
@@ -89,7 +89,7 @@ public:
net::Poll poller;
while (sent < BYTES_TO_SEND && outgoing->connectionState() != CS_CLOSED) {
const int to_send = step - off;
- const int ret = outgoing->send((const bt::Uint8 *)data.data() + off, to_send);
+ const int ret = outgoing->send(data_view.sliced(off, to_send));
if (ret > 0) {
hgen.update(data_view.sliced(off, ret));
sent += ret;
diff --git a/src/utp/tests/utppolltest.cpp b/src/utp/tests/utppolltest.cpp
index 71d3cf67..521bdbb8 100644
--- a/src/utp/tests/utppolltest.cpp
+++ b/src/utp/tests/utppolltest.cpp
@@ -133,7 +133,7 @@ private:
continue;
}
- const int ret = outgoing[i]->send((const bt::Uint8 *)test, strlen(test));
+ const int ret = outgoing[i]->send(test);
QCOMPARE(ret, (int)strlen(test));
bs.set(i, true);
}
diff --git a/src/utp/utpsocket.cpp b/src/utp/utpsocket.cpp
index 045be909..60124468 100644
--- a/src/utp/utpsocket.cpp
+++ b/src/utp/utpsocket.cpp
@@ -164,7 +164,7 @@ void UTPSocket::reset()
conn.clear();
}
-int UTPSocket::send(const bt::Uint8 *buf, int len)
+int UTPSocket::send(QByteArrayView buf)
{
const Connection::Ptr ptr = conn.toStrongRef();
if (!ptr) {
@@ -172,7 +172,7 @@ int UTPSocket::send(const bt::Uint8 *buf, int len)
}
try {
- return ptr->send(buf, len);
+ return ptr->send(buf);
} catch (Connection::TransmissionError &err) {
close();
return -1;
diff --git a/src/utp/utpsocket.h b/src/utp/utpsocket.h
index 260364d3..9c23af92 100644
--- a/src/utp/utpsocket.h
+++ b/src/utp/utpsocket.h
@@ -27,7 +27,7 @@ public:
int fd() const override;
bool ok() const override;
- int send(const bt::Uint8 *buf, int len) override;
+ int send(QByteArrayView buf) override;
int recv(bt::Uint8 *buf, int max_len) override;
void close() override;
void setBlocking(bool on) override;