Permalink
Browse files

MythSocket: Re-enable setReceiveBufferSize() and setAddressReusable()

These were supported as calls in the Qt3 QSocketDevice but are not
yet supported in Qt4's QTcpSocket. Instead I've added some code to
handle this using setsockopt() in the ConnectHandler().
  • Loading branch information...
daniel-kristjansson committed Oct 15, 2012
1 parent dae00d3 commit db8e0fa09f904367a84f47f4186bf5334e2be7e0
Showing with 34 additions and 5 deletions.
  1. +33 −4 mythtv/libs/libmythbase/mythsocket.cpp
  2. +1 −1 mythtv/libs/libmythbase/mythsocket.h
@@ -1,3 +1,12 @@
// setsockopt
#ifdef Q_OS_WIN32
#include <winsock2.h>
#include <Ws2tcpip.h>
#include <stdio.h>
#else
#include <sys/socket.h>
#endif
// Qt
#include <QNetworkInterface> // for QNetworkInterface::allAddresses ()
#include <QCoreApplication>
@@ -22,10 +31,11 @@
.arg(a->GetSocketDescriptor())
#define LOC SLOC(this)
const uint MythSocket::kSocketBufferSize = 128 * 1024;
const uint MythSocket::kShortTimeout = kMythSocketShortTimeout;
const uint MythSocket::kLongTimeout = kMythSocketLongTimeout;
const int MythSocket::kSocketReceiveBufferSize = 128 * 1024;
QMutex MythSocket::s_loopbackCacheLock;
QHash<QString, QHostAddress::SpecialAddress> MythSocket::s_loopbackCache;
@@ -170,6 +180,28 @@ void MythSocket::ConnectHandler(void)
m_tcpSocket->setSocketOption(QAbstractSocket::LowDelayOption, QVariant(1));
m_tcpSocket->setSocketOption(QAbstractSocket::KeepAliveOption, QVariant(1));
#if defined(Q_OS_WIN32)
BOOL reuse_addr_val = TRUE;
#else
int reuse_addr_val = 1;
#endif
int ret = setsockopt(m_tcpSocket->socketDescriptor(), SOL_SOCKET,
SO_REUSEADDR, &reuse_addr_val,
sizeof(reuse_addr_val));
if (ret < 0)
{
LOG(VB_SOCKET, LOG_INFO, LOC + "Failed to set SO_REUSEADDR" + ENO);
}
int rcv_buf_val = kSocketReceiveBufferSize;
ret = setsockopt(m_tcpSocket->socketDescriptor(), SOL_SOCKET,
SO_RCVBUF, &rcv_buf_val,
sizeof(rcv_buf_val));
if (ret < 0)
{
LOG(VB_SOCKET, LOG_INFO, LOC + "Failed to set SO_RCVBUF" + ENO);
}
if (m_callback)
{
LOG(VB_SOCKET, LOG_DEBUG, LOC +
@@ -568,9 +600,6 @@ void MythSocket::ConnectToHostReal(QHostAddress addr, quint16 port, bool *ret)
m_tcpSocket->connectToHost(addr, port, QAbstractSocket::ReadWrite);
//setReceiveBufferSize(kSocketBufferSize);
//setAddressReusable(true);
bool ok = m_tcpSocket->waitForConnected();
if (ok)
@@ -112,7 +112,7 @@ class MBASE_PUBLIC MythSocket : public QObject, public ReferenceCounter
bool m_isAnnounced; // only set in thread using MythSocket
QStringList m_announce; // only set in thread using MythSocket
static const uint kSocketBufferSize;
static const int kSocketReceiveBufferSize;
static QMutex s_loopbackCacheLock;
static QHash<QString, QHostAddress::SpecialAddress> s_loopbackCache;

0 comments on commit db8e0fa

Please sign in to comment.