kio: stream PID as qint64 type

the static_cast<T>()'s are just for compile-time checks

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2022-09-26 14:47:24 +03:00
parent a12fea1aef
commit a87347ea27
3 changed files with 10 additions and 35 deletions

View file

@ -80,10 +80,6 @@ IdleSlave::IdleSlave(QObject *parent)
mOnHold = false;
}
template<int T> struct PIDType { typedef pid_t PID_t; } ;
template<> struct PIDType<2> { typedef qint16 PID_t; } ;
template<> struct PIDType<4> { typedef qint32 PID_t; } ;
void
IdleSlave::gotInput()
{
@ -107,14 +103,12 @@ IdleSlave::gotInput()
else
{
QDataStream stream( data );
PIDType<sizeof(pid_t)>::PID_t stream_pid;
pid_t pid;
qint64 pid;
QByteArray protocol;
QString host;
qint8 b;
stream >> stream_pid >> protocol >> host >> b;
pid = stream_pid;
// Overload with (bool) onHold, (KUrl) url.
stream >> pid >> protocol >> host >> b;
// Overload with (bool) onHold, (KUrl) url.
if (!stream.atEnd())
{
KUrl url;
@ -123,7 +117,7 @@ IdleSlave::gotInput()
mUrl = url;
}
mPid = pid;
mPid = static_cast<pid_t>(pid);
mConnected = (b != 0);
mProtocol = QString::fromLatin1(protocol);
mHost = host;
@ -595,11 +589,10 @@ KLauncher::requestDone(KLaunchRequest *request)
if ( requestResult.dbusName.isNull() ) // null strings can't be sent
requestResult.dbusName.clear();
Q_ASSERT( !requestResult.error.isNull() );
PIDType<sizeof(pid_t)>::PID_t stream_pid = requestResult.pid;
QDBusConnection::sessionBus().send(request->transaction.createReply(QVariantList() << requestResult.result
<< requestResult.dbusName
<< requestResult.error
<< stream_pid));
<< static_cast<qint64>(requestResult.pid)));
}
#ifdef KLAUNCHER_VERBOSE_OUTPUT
kDebug(7016) << "removing done request" << request->name << "PID" << request->pid;

View file

@ -494,19 +494,11 @@ void SlaveBase::needSubUrlData()
send( MSG_NEED_SUBURL_DATA );
}
/*
* Map pid_t to a signed integer type that makes sense for QByteArray;
* only the most common sizes 16 bit and 32 bit are special-cased.
*/
template<int T> struct PIDType { typedef pid_t PID_t; } ;
template<> struct PIDType<2> { typedef qint16 PID_t; } ;
template<> struct PIDType<4> { typedef qint32 PID_t; } ;
void SlaveBase::slaveStatus( const QString &host, bool connected )
{
pid_t pid = getpid();
qint64 pid = static_cast<qint64>(::getpid());
qint8 b = connected ? 1 : 0;
KIO_DATA << (PIDType<sizeof(pid_t)>::PID_t)pid << mProtocol << host << b;
KIO_DATA << pid << mProtocol << host << b;
if (d->onHold)
stream << d->onHoldUrl;
send( MSG_SLAVE_STATUS, data );

View file

@ -128,14 +128,6 @@ void SlaveInterface::calcSpeed()
}
}
/*
* Map pid_t to a signed integer type that makes sense for QByteArray;
* only the most common sizes 16 bit and 32 bit are special-cased.
*/
template<int T> struct PIDType { typedef pid_t PID_t; } ;
template<> struct PIDType<2> { typedef qint16 PID_t; } ;
template<> struct PIDType<4> { typedef qint32 PID_t; } ;
bool SlaveInterface::dispatch(int cmd, const QByteArray &rawdata)
{
Q_D(SlaveInterface);
@ -201,14 +193,12 @@ bool SlaveInterface::dispatch(int cmd, const QByteArray &rawdata)
break;
}
case MSG_SLAVE_STATUS: {
PIDType<sizeof(pid_t)>::PID_t stream_pid;
pid_t pid;
qint64 pid;
QByteArray protocol;
QString str;
qint8 b;
stream >> stream_pid >> protocol >> str >> b;
pid = stream_pid;
emit slaveStatus(pid, protocol, str, (b != 0));
stream >> pid >> protocol >> str >> b;
emit slaveStatus(static_cast<pid_t>(pid), protocol, str, (b != 0));
break;
}
case MSG_CONNECTED: {