Fixed uninitialized members

This commit is contained in:
Albert Vaca 2015-04-04 10:05:55 -07:00
parent 70e3aec278
commit 6c6f2b1a03
8 changed files with 62 additions and 48 deletions

View file

@ -29,38 +29,14 @@
#include <QHostInfo> #include <QHostInfo>
#include <QTcpServer> #include <QTcpServer>
#include <QUdpSocket> #include <QUdpSocket>
#include <QtGlobal>
#include "landevicelink.h" #include "landevicelink.h"
#include <kdeconnectconfig.h> #include <kdeconnectconfig.h>
void LanLinkProvider::configureSocket(QTcpSocket* socket)
{
int fd = socket->socketDescriptor();
socket->setSocketOption(QAbstractSocket::KeepAliveOption, QVariant(1));
#ifdef TCP_KEEPIDLE
// time to start sending keepalive packets (seconds)
int maxIdle = 10;
setsockopt(fd, IPPROTO_TCP, TCP_KEEPIDLE, &maxIdle, sizeof(maxIdle));
#endif
#ifdef TCP_KEEPINTVL
// interval between keepalive packets after the initial period (seconds)
int interval = 5;
setsockopt(fd, IPPROTO_TCP, TCP_KEEPINTVL, &interval, sizeof(interval));
#endif
#ifdef TCP_KEEPCNT
// number of missed keepalive packets before disconnecting
int count = 3;
setsockopt(fd, IPPROTO_TCP, TCP_KEEPCNT, &count, sizeof(count));
#endif
}
LanLinkProvider::LanLinkProvider() LanLinkProvider::LanLinkProvider()
{ {
mTcpPort = 0;
mUdpServer = new QUdpSocket(this); mUdpServer = new QUdpSocket(this);
connect(mUdpServer, SIGNAL(readyRead()), this, SLOT(newUdpConnection())); connect(mUdpServer, SIGNAL(readyRead()), this, SLOT(newUdpConnection()));
@ -70,6 +46,11 @@ LanLinkProvider::LanLinkProvider()
} }
LanLinkProvider::~LanLinkProvider()
{
}
void LanLinkProvider::onStart() void LanLinkProvider::onStart()
{ {
mUdpServer->bind(QHostAddress::Any, port, QUdpSocket::ShareAddress); mUdpServer->bind(QHostAddress::Any, port, QUdpSocket::ShareAddress);
@ -102,6 +83,8 @@ void LanLinkProvider::onNetworkChange(QNetworkSession::State state)
return; return;
} }
Q_ASSERT(mTcpPort != 0);
NetworkPackage np(""); NetworkPackage np("");
NetworkPackage::createIdentityPackage(&np); NetworkPackage::createIdentityPackage(&np);
np.set("tcpPort", mTcpPort); np.set("tcpPort", mTcpPort);
@ -295,7 +278,28 @@ void LanLinkProvider::deviceLinkDestroyed(QObject* destroyedDeviceLink)
} }
LanLinkProvider::~LanLinkProvider() void LanLinkProvider::configureSocket(QTcpSocket* socket)
{ {
int fd = socket->socketDescriptor();
socket->setSocketOption(QAbstractSocket::KeepAliveOption, QVariant(1));
#ifdef TCP_KEEPIDLE
// time to start sending keepalive packets (seconds)
int maxIdle = 10;
setsockopt(fd, IPPROTO_TCP, TCP_KEEPIDLE, &maxIdle, sizeof(maxIdle));
#endif
#ifdef TCP_KEEPINTVL
// interval between keepalive packets after the initial period (seconds)
int interval = 5;
setsockopt(fd, IPPROTO_TCP, TCP_KEEPINTVL, &interval, sizeof(interval));
#endif
#ifdef TCP_KEEPCNT
// number of missed keepalive packets before disconnecting
int count = 3;
setsockopt(fd, IPPROTO_TCP, TCP_KEEPCNT, &count, sizeof(count));
#endif
} }

View file

@ -19,6 +19,7 @@
*/ */
#include <qalgorithms.h> #include <qalgorithms.h>
#include <QtGlobal>
#include "uploadjob.h" #include "uploadjob.h"
#include "core_debug.h" #include "core_debug.h"
@ -28,6 +29,7 @@ UploadJob::UploadJob(const QSharedPointer<QIODevice>& source): KJob()
mInput = source; mInput = source;
mServer = new QTcpServer(this); mServer = new QTcpServer(this);
mSocket = 0; mSocket = 0;
mPort = 0;
connect(mInput.data(), SIGNAL(readyRead()), this, SLOT(readyRead())); connect(mInput.data(), SIGNAL(readyRead()), this, SLOT(readyRead()));
connect(mInput.data(), SIGNAL(aboutToClose()), this, SLOT(aboutToClose())); connect(mInput.data(), SIGNAL(aboutToClose()), this, SLOT(aboutToClose()));
@ -91,10 +93,10 @@ void UploadJob::aboutToClose()
QVariantMap UploadJob::getTransferInfo() QVariantMap UploadJob::getTransferInfo()
{ {
Q_ASSERT(mPort != 0);
QVariantMap ret; QVariantMap ret;
ret["port"] = mPort; ret["port"] = mPort;
return ret; return ret;
} }

View file

@ -42,7 +42,7 @@ private:
QSharedPointer<QIODevice> mInput; QSharedPointer<QIODevice> mInput;
QTcpServer* mServer; QTcpServer* mServer;
QTcpSocket* mSocket; QTcpSocket* mSocket;
qint16 mPort; quint16 mPort;
private Q_SLOTS: private Q_SLOTS:
void readyRead(); void readyRead();

View file

@ -128,7 +128,7 @@ void FileTransferJob::readyRead()
//If a least 1 second has passed since last update //If a least 1 second has passed since last update
int secondsSinceLastTime = mTime.secsTo(QTime::currentTime()); int secondsSinceLastTime = mTime.secsTo(QTime::currentTime());
if (secondsSinceLastTime > 0 && mSpeedBytes > 0) { if (secondsSinceLastTime > 0 && mSpeedBytes > 0) {
float speed = (mWritten - mSpeedBytes) / secondsSinceLastTime; float speed = (mWritten - mSpeedBytes) / float(secondsSinceLastTime);
emitSpeed(speed); emitSpeed(speed);
mTime = QTime::currentTime(); mTime = QTime::currentTime();

View file

@ -26,6 +26,8 @@
BatteryDbusInterface::BatteryDbusInterface(const Device *device) BatteryDbusInterface::BatteryDbusInterface(const Device *device)
: QDBusAbstractAdaptor(const_cast<Device*>(device)) : QDBusAbstractAdaptor(const_cast<Device*>(device))
, mCharge(-1)
, mIsCharging(false)
{ {
} }

View file

@ -46,7 +46,7 @@ Q_SIGNALS:
private: private:
int mCharge; int mCharge;
bool mIsCharging : 1; bool mIsCharging;
}; };

View file

@ -40,6 +40,7 @@ Q_LOGGING_CATEGORY(KDECONNECT_PLUGIN_MPRIS, "kdeconnect.plugin.mpris")
MprisControlPlugin::MprisControlPlugin(QObject* parent, const QVariantList& args) MprisControlPlugin::MprisControlPlugin(QObject* parent, const QVariantList& args)
: KdeConnectPlugin(parent, args) : KdeConnectPlugin(parent, args)
{ {
prevVolume = -1;
//Detect new interfaces //Detect new interfaces
connect(QDBusConnection::sessionBus().interface(), SIGNAL(serviceOwnerChanged(QString,QString,QString)), connect(QDBusConnection::sessionBus().interface(), SIGNAL(serviceOwnerChanged(QString,QString,QString)),

View file

@ -48,14 +48,17 @@ ScreensaverInhibitPlugin::ScreensaverInhibitPlugin(QObject* parent, const QVaria
if (reply.errorMessage() != NULL) { if (reply.errorMessage() != NULL) {
qCDebug(KDECONNECT_PLUGIN_SCREENSAVERINHIBIT) << "Unable to inhibit the screensaver: " << reply.errorMessage(); qCDebug(KDECONNECT_PLUGIN_SCREENSAVERINHIBIT) << "Unable to inhibit the screensaver: " << reply.errorMessage();
inhibitCookie = 0;
} else { } else {
// Store the cookie we receive, this will be sent back when sending the uninhibit call. // Store the cookie we receive, this will be sent back when sending the uninhibit call.
this->inhibitCookie = reply.arguments().first().toUInt(); inhibitCookie = reply.arguments().first().toUInt();
} }
} }
ScreensaverInhibitPlugin::~ScreensaverInhibitPlugin() ScreensaverInhibitPlugin::~ScreensaverInhibitPlugin()
{ {
if (inhibitCookie == 0) return;
QDBusInterface inhibitInterface(INHIBIT_SERVICE, INHIBIT_PATH, INHIBIT_INTERFACE); QDBusInterface inhibitInterface(INHIBIT_SERVICE, INHIBIT_PATH, INHIBIT_INTERFACE);
inhibitInterface.call(UNINHIBIT_METHOD, this->inhibitCookie); inhibitInterface.call(UNINHIBIT_METHOD, this->inhibitCookie);
@ -69,7 +72,9 @@ ScreensaverInhibitPlugin::~ScreensaverInhibitPlugin()
} }
void ScreensaverInhibitPlugin::connected() void ScreensaverInhibitPlugin::connected()
{} {
}
bool ScreensaverInhibitPlugin::receivePackage(const NetworkPackage& np) bool ScreensaverInhibitPlugin::receivePackage(const NetworkPackage& np)
{ {