mirror of
https://github.com/itay-grudev/SingleApplication.git
synced 2025-01-15 17:02:06 +08:00
Fixed shadow variable warning (#21)
This commit is contained in:
parent
795e9a5d3a
commit
c7b8e20905
@ -252,27 +252,27 @@ void SingleApplicationPrivate::slotConnectionEstablished()
|
|||||||
{
|
{
|
||||||
Q_Q(SingleApplication);
|
Q_Q(SingleApplication);
|
||||||
|
|
||||||
QLocalSocket *socket = server->nextPendingConnection();
|
QLocalSocket *nextConnSocket = server->nextPendingConnection();
|
||||||
|
|
||||||
// Verify that the new connection follows the SingleApplication protocol
|
// Verify that the new connection follows the SingleApplication protocol
|
||||||
char connectionType = '\0'; // Invalid connection
|
char connectionType = '\0'; // Invalid connection
|
||||||
quint32 instanceId;
|
quint32 instanceId;
|
||||||
QByteArray initMsg, tmp;
|
QByteArray initMsg, tmp;
|
||||||
if( socket->waitForReadyRead( 100 ) ) {
|
if( nextConnSocket->waitForReadyRead( 100 ) ) {
|
||||||
tmp = socket->read( blockServerName.length() );
|
tmp = nextConnSocket->read( blockServerName.length() );
|
||||||
// Verify that the socket data start with blockServerName
|
// Verify that the socket data start with blockServerName
|
||||||
if( tmp == blockServerName.toLatin1() ) {
|
if( tmp == blockServerName.toLatin1() ) {
|
||||||
initMsg = tmp;
|
initMsg = tmp;
|
||||||
// Verify that the next charecter is N/S/R (connecion type)
|
// Verify that the next character is N/S/R (connection type)
|
||||||
// Stands for New Instance/Secondary Instance/Reconnect
|
// Stands for New Instance/Secondary Instance/Reconnect
|
||||||
connectionType = socket->read( 1 )[0];
|
connectionType = nextConnSocket->read( 1 )[0];
|
||||||
switch( connectionType ) {
|
switch( connectionType ) {
|
||||||
case 'N':
|
case 'N':
|
||||||
case 'S':
|
case 'S':
|
||||||
case 'R':
|
case 'R':
|
||||||
{
|
{
|
||||||
initMsg += connectionType;
|
initMsg += connectionType;
|
||||||
tmp = socket->read( sizeof(quint32) );
|
tmp = nextConnSocket->read( sizeof(quint32) );
|
||||||
const char * data = tmp.constData();
|
const char * data = tmp.constData();
|
||||||
instanceId = (quint32)*data;
|
instanceId = (quint32)*data;
|
||||||
initMsg += tmp;
|
initMsg += tmp;
|
||||||
@ -281,7 +281,7 @@ void SingleApplicationPrivate::slotConnectionEstablished()
|
|||||||
qChecksum( initMsg.constData(), initMsg.length() ),
|
qChecksum( initMsg.constData(), initMsg.length() ),
|
||||||
256
|
256
|
||||||
);
|
);
|
||||||
tmp = socket->read( checksum.length() );
|
tmp = nextConnSocket->read( checksum.length() );
|
||||||
if( checksum == tmp )
|
if( checksum == tmp )
|
||||||
break; // Otherwise set to invalid connection (next line)
|
break; // Otherwise set to invalid connection (next line)
|
||||||
}
|
}
|
||||||
@ -292,26 +292,26 @@ void SingleApplicationPrivate::slotConnectionEstablished()
|
|||||||
}
|
}
|
||||||
|
|
||||||
if( connectionType == '\0' ) {
|
if( connectionType == '\0' ) {
|
||||||
socket->close();
|
nextConnSocket->close();
|
||||||
delete socket;
|
delete nextConnSocket;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QObject::connect(
|
QObject::connect(
|
||||||
socket,
|
nextConnSocket,
|
||||||
&QLocalSocket::aboutToClose,
|
&QLocalSocket::aboutToClose,
|
||||||
this,
|
this,
|
||||||
[socket, instanceId, this]() {
|
[nextConnSocket, instanceId, this]() {
|
||||||
Q_EMIT this->slotClientConnectionClosed( socket, instanceId );
|
Q_EMIT this->slotClientConnectionClosed( nextConnSocket, instanceId );
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
QObject::connect(
|
QObject::connect(
|
||||||
socket,
|
nextConnSocket,
|
||||||
&QLocalSocket::readyRead,
|
&QLocalSocket::readyRead,
|
||||||
this,
|
this,
|
||||||
[socket, instanceId, this]() {
|
[nextConnSocket, instanceId, this]() {
|
||||||
Q_EMIT this->slotDataAvailable( socket, instanceId );
|
Q_EMIT this->slotDataAvailable( nextConnSocket, instanceId );
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -323,22 +323,22 @@ void SingleApplicationPrivate::slotConnectionEstablished()
|
|||||||
Q_EMIT q->instanceStarted();
|
Q_EMIT q->instanceStarted();
|
||||||
}
|
}
|
||||||
|
|
||||||
if( socket->bytesAvailable() > 0 ) {
|
if( nextConnSocket->bytesAvailable() > 0 ) {
|
||||||
Q_EMIT this->slotDataAvailable( socket, instanceId );
|
Q_EMIT this->slotDataAvailable( nextConnSocket, instanceId );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SingleApplicationPrivate::slotDataAvailable( QLocalSocket *socket, quint32 instanceId )
|
void SingleApplicationPrivate::slotDataAvailable( QLocalSocket *dataSocket, quint32 instanceId )
|
||||||
{
|
{
|
||||||
Q_Q(SingleApplication);
|
Q_Q(SingleApplication);
|
||||||
Q_EMIT q->receivedMessage( instanceId, socket->readAll() );
|
Q_EMIT q->receivedMessage( instanceId, dataSocket->readAll() );
|
||||||
}
|
}
|
||||||
|
|
||||||
void SingleApplicationPrivate::slotClientConnectionClosed( QLocalSocket *socket, quint32 instanceId )
|
void SingleApplicationPrivate::slotClientConnectionClosed( QLocalSocket *closedSocket, quint32 instanceId )
|
||||||
{
|
{
|
||||||
if( socket->bytesAvailable() > 0 )
|
if( closedSocket->bytesAvailable() > 0 )
|
||||||
Q_EMIT slotDataAvailable( socket, instanceId );
|
Q_EMIT slotDataAvailable( closedSocket, instanceId );
|
||||||
socket->deleteLater();
|
closedSocket->deleteLater();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user