mirror of
https://github.com/itay-grudev/SingleApplication.git
synced 2024-11-15 12:15:43 +08:00
Refactored slotConnectionEstablished()
The code is now shorter and easier to understand. Fixed an uninitialised variable warning as reported in #20.
This commit is contained in:
parent
3d178904f0
commit
60d30db837
@ -264,21 +264,23 @@ void SingleApplicationPrivate::slotConnectionEstablished()
|
||||
QLocalSocket *socket = server->nextPendingConnection();
|
||||
|
||||
// Verify that the new connection follows the SingleApplication protocol
|
||||
char connectionType;
|
||||
char connectionType = '\0'; // Invalid connection
|
||||
quint32 instanceId;
|
||||
QByteArray initMsg, tmp;
|
||||
bool invalidConnection = false;
|
||||
if( socket->waitForReadyRead( 100 ) ) {
|
||||
tmp = socket->read( blockServerName.length() );
|
||||
// Verify that the socket data start with blockServerName
|
||||
if( tmp == blockServerName.toLatin1() ) {
|
||||
initMsg = tmp;
|
||||
tmp = socket->read(1);
|
||||
// Verify that the next charecter is N/S/R (connecion type)
|
||||
// Stands for New Instance/Secondary Instance/Reconnect
|
||||
if( tmp == "N" || tmp == "S" || tmp == "R" ) {
|
||||
connectionType = tmp.at(0);
|
||||
initMsg += tmp;
|
||||
connectionType = socket->read( 1 )[0];
|
||||
switch( connectionType ) {
|
||||
case 'N':
|
||||
case 'S':
|
||||
case 'R':
|
||||
{
|
||||
initMsg += connectionType;
|
||||
tmp = socket->read( sizeof(quint32) );
|
||||
const char * data = tmp.constData();
|
||||
instanceId = (quint32)*data;
|
||||
@ -289,20 +291,16 @@ void SingleApplicationPrivate::slotConnectionEstablished()
|
||||
256
|
||||
);
|
||||
tmp = socket->read( checksum.length() );
|
||||
if( checksum != tmp ) {
|
||||
invalidConnection = true;
|
||||
}
|
||||
} else {
|
||||
invalidConnection = true;
|
||||
if( checksum == tmp )
|
||||
break; // Otherwise set to invalid connection (next line)
|
||||
}
|
||||
default:
|
||||
connectionType = '\0'; // Invalid connection
|
||||
}
|
||||
} else {
|
||||
invalidConnection = true;
|
||||
}
|
||||
} else {
|
||||
invalidConnection = true;
|
||||
}
|
||||
|
||||
if( invalidConnection ) {
|
||||
if( connectionType == '\0' ) {
|
||||
socket->close();
|
||||
delete socket;
|
||||
return;
|
||||
|
Loading…
Reference in New Issue
Block a user