From 492bc75d6861228d178813b2e73ec0351455cd62 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Wed, 20 Apr 2016 15:58:01 -0700 Subject: [PATCH 1/2] Reduce max packet size to 1492 --- libraries/networking/src/udt/Constants.h | 2 +- tools/udt-test/src/UDTTest.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libraries/networking/src/udt/Constants.h b/libraries/networking/src/udt/Constants.h index 98569ead5a..3186571f9b 100644 --- a/libraries/networking/src/udt/Constants.h +++ b/libraries/networking/src/udt/Constants.h @@ -18,7 +18,7 @@ namespace udt { static const int UDP_IPV4_HEADER_SIZE = 28; - static const int MAX_PACKET_SIZE_WITH_UDP_HEADER = 1500; + static const int MAX_PACKET_SIZE_WITH_UDP_HEADER = 1492; static const int MAX_PACKET_SIZE = MAX_PACKET_SIZE_WITH_UDP_HEADER - UDP_IPV4_HEADER_SIZE; static const int MAX_PACKETS_IN_FLIGHT = 25600; static const int CONNECTION_RECEIVE_BUFFER_SIZE_PACKETS = 8192; diff --git a/tools/udt-test/src/UDTTest.cpp b/tools/udt-test/src/UDTTest.cpp index 2f2e896d87..0a00691ebe 100644 --- a/tools/udt-test/src/UDTTest.cpp +++ b/tools/udt-test/src/UDTTest.cpp @@ -25,7 +25,7 @@ const QCommandLineOption TARGET_OPTION { "IP:PORT or HOSTNAME:PORT" }; const QCommandLineOption PACKET_SIZE { - "packet-size", "size for sent packets in bytes (defaults to 1500)", "bytes", + "packet-size", "size for sent packets in bytes (defaults to 1492)", "bytes", QString(udt::MAX_PACKET_SIZE_WITH_UDP_HEADER) }; const QCommandLineOption MIN_PACKET_SIZE { @@ -366,7 +366,7 @@ void UDTTest::sampleStats() { static const double USECS_PER_MSEC = 1000.0; static const double MEGABITS_PER_BYTE = 8.0 / 1000000.0; static const double MS_PER_SECOND = 1000.0; - static const double PPS_TO_MBPS = 1500.0 * MEGABITS_PER_BYTE; + static const double PPS_TO_MBPS = udt::MAX_PACKET_SIZE_WITH_UDP_HEADER * MEGABITS_PER_BYTE; if (!_target.isNull()) { From 778c19d7e404a3abf0ffdb421dcd6de5bf8f3202 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Wed, 20 Apr 2016 15:58:25 -0700 Subject: [PATCH 2/2] Make sure the socket allows fragmenting --- libraries/networking/src/udt/Socket.cpp | 15 +++++++++++++++ libraries/networking/src/udt/Socket.h | 2 +- tools/udt-test/src/UDTTest.cpp | 6 +++--- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/libraries/networking/src/udt/Socket.cpp b/libraries/networking/src/udt/Socket.cpp index 0695a65e1f..cf66847b6c 100644 --- a/libraries/networking/src/udt/Socket.cpp +++ b/libraries/networking/src/udt/Socket.cpp @@ -38,6 +38,21 @@ Socket::Socket(QObject* parent) : _synTimer->start(_synInterval); } +void Socket::bind(const QHostAddress& address, quint16 port) { + _udpSocket.bind(address, port); + setSystemBufferSizes(); + +#if defined(Q_OS_LINUX) + auto sd = _udpSocket.socketDescriptor(); + int val = IP_PMTUDISC_DONT; + setsockopt(sd, IPPROTO_IP, IP_MTU_DISCOVER, &val, sizeof(val)); +#elif defined(Q_OS_WINDOWS) + auto sd = _udpSocket.socketDescriptor(); + int val = 0; // false + setsockopt(sd, IPPROTO_IP, IP_DONTFRAGMENT, &val, sizeof(val)); +#endif +} + void Socket::rebind() { quint16 oldPort = _udpSocket.localPort(); diff --git a/libraries/networking/src/udt/Socket.h b/libraries/networking/src/udt/Socket.h index 424158045f..35a32a034f 100644 --- a/libraries/networking/src/udt/Socket.h +++ b/libraries/networking/src/udt/Socket.h @@ -60,7 +60,7 @@ public: qint64 writeDatagram(const char* data, qint64 size, const HifiSockAddr& sockAddr); qint64 writeDatagram(const QByteArray& datagram, const HifiSockAddr& sockAddr); - void bind(const QHostAddress& address, quint16 port = 0) { _udpSocket.bind(address, port); setSystemBufferSizes(); } + void bind(const QHostAddress& address, quint16 port = 0); void rebind(); void setPacketFilterOperator(PacketFilterOperator filterOperator) { _packetFilterOperator = filterOperator; } diff --git a/tools/udt-test/src/UDTTest.cpp b/tools/udt-test/src/UDTTest.cpp index 0a00691ebe..af94d2294b 100644 --- a/tools/udt-test/src/UDTTest.cpp +++ b/tools/udt-test/src/UDTTest.cpp @@ -25,8 +25,8 @@ const QCommandLineOption TARGET_OPTION { "IP:PORT or HOSTNAME:PORT" }; const QCommandLineOption PACKET_SIZE { - "packet-size", "size for sent packets in bytes (defaults to 1492)", "bytes", - QString(udt::MAX_PACKET_SIZE_WITH_UDP_HEADER) + "packet-size", "size for sent packets in bytes (defaults to " + QString(MAX_PACKET_SIZE) + ")", "bytes", + QString(udt::MAX_PACKET_SIZE) }; const QCommandLineOption MIN_PACKET_SIZE { "min-packet-size", "min size for sent packets in bytes", "min bytes" @@ -366,7 +366,7 @@ void UDTTest::sampleStats() { static const double USECS_PER_MSEC = 1000.0; static const double MEGABITS_PER_BYTE = 8.0 / 1000000.0; static const double MS_PER_SECOND = 1000.0; - static const double PPS_TO_MBPS = udt::MAX_PACKET_SIZE_WITH_UDP_HEADER * MEGABITS_PER_BYTE; + static const double PPS_TO_MBPS = udt::MAX_PACKET_SIZE * MEGABITS_PER_BYTE; if (!_target.isNull()) {