Commit Graph

20 Commits

Author SHA1 Message Date
Nils Jeisecke
25a7b60982 Ensure data sent via SingleApplication::sendMessage is received completely
Whilst the initial "connect" message is framed with a length header,
this was missing for the user data.

Thus there was no guarantee that the message frame was really received
completely on emitting the "receivedMessage" signal.

This change splits the previous "StageConnected" state into
"StageConnectedHeader" and "StageConnectedBody" and does some
refactoring to allow using the same write and read functions as the
"init" messages.
2021-06-01 04:10:53 +02:00
Nils Jeisecke
0c458ec8c9 Add simple acknowledge protocol to ensure the server has received all data
The server now acknowledges every received message by sending a \r.

By waiting for the acknowledgement, clients should no longer terminate
too early, causing bytes getting lost in Qt's internal socket handling.

Message handling in the server is simplified because we can now rely
on the readyRead signal being raised for every frame.

This should finally solve #125 and #121.

What remains is to correctly handle data sent using
SingleApplication::sendMessage.
2021-05-31 16:12:32 +02:00
Loren Burkholder
f236032cf9 Allow adding unique userdata to instances 2020-12-16 22:17:24 -05:00
Shatur95
e17c715faf Fix Clang Tidy warnings
readability-convert-member-functions-to-static
readability-static-accessed-through-instance
readability-make-member-function-const
readability-inconsistent-declaration-parameter-name
2020-10-15 21:41:00 +03:00
Itay Grudev
3e83f5ce13 Improved the connectToPrimary() method and fixed issue with instanceStarted() not getting emitted 2020-09-09 02:28:07 +01:00
Itay Grudev
eca5803665 Moved the random sleep functionality to SingleApplicationPrivate 2020-09-09 02:23:42 +01:00
Itay Grudev
e4282f2476 Mitigated possible race condition during app startup 2020-09-09 00:28:02 +01:00
Shatur95
fcd4fcab21 Fix Clang Tidy warnings 2020-05-17 17:50:27 +03:00
Itay Grudev
9dd775feed
Update singleapplication_p.h 2020-04-22 00:57:56 +01:00
Leander Schulten
49c282a64c The codec for string from qgetenv and pw->pw_name is not necessarily utf8. So use QString::fromLocal8Bit and QStrings. 2020-03-27 07:52:48 +01:00
Itay Grudev
81cc2719be v3.1.0a Added primaryUser()
Closes #95
2020-03-03 01:24:55 +00:00
Francis Giraldeau
0db27016b0 Async socket processing (#49)
* Process socket events asynchronously

Avoid blocking the event loop using waitForReadyRead(). Instead, process the
initialization in two phases. It was necessary to add a map to keep track of
the state of the initial message processing

Signed-off-by: Francis Giraldeau <francis.giraldeau@nrc-cnrc.gc.ca>

* Fix undefined variable on Windows

The timout variable does not exists in this scope, we can safely remove the
Q_UNUSED.

Signed-off-by: Francis Giraldeau <francis.giraldeau@nrc-cnrc.gc.ca>

* Fix validation logic of initial message

I modified the logic to a positive value, but the modification was incomplete
and caused the initial message to be incorrectly considered as invalid.

Signed-off-by: Francis Giraldeau <francis.giraldeau@nrc-cnrc.gc.ca>

* Use the proper socket when receiving message

The socket variable is a class member, but we really want to use
nextConnSocket when receiving the message in the lambda.

Signed-off-by: Francis Giraldeau <francis.giraldeau@nrc-cnrc.gc.ca>
2018-09-10 22:35:38 +01:00
Itay Grudev
9357d19042
v3.0.12a Removed custom signal handling. 2018-07-27 12:59:31 +03:00
Itay Grudev
46b2204a3f
Proposed SA changes still containing a race condition (#48) 2018-07-27 04:29:55 +03:00
Jedidiah Buck McCready
a956ae47d1 removed c style casts and eliminated all clang warnings, ... (#38)
* removed c style casts and eliminated all clang warnings, fixed instanceId reading from only one byte in deserialization of message, cleaned up serialization code using QDataStream, changed connection type to use quint8 enum rather than char

* renamed SingleAppConnectionType to ConnectionType, added initialization values to all ConnectionType enum cases
2017-12-03 17:04:02 +00:00
Itay Grudev
4f03651072 Primary PID support (#36)
* Added the ability to bring the primary application window to the foreground on Windows systems by adding an option flag. THis option can only be used in Windows development and in applications derived from QApplication with a QMainWindow object.
Because the primary application needs to be instructed to go to the foreground, the option SecondaryNotification must also be set to use this functionality

* Changed the ability to bring the primary application window to the front as discussed in itay-grudev/SingleApplication#31.

Now the process ID of the primary application get stored and is accessible for other instances of the application. It is to the developer to bring the applications windows to the front. For convenience the accompanying readme now contains a paragraph with example of how to do this on Windows systems.

* v3.0.9 Added SingleApplicationPrivate::primaryPid()
2017-10-02 12:17:41 +01:00
Itay Grudev
c2a6faca68 Removed QMutex for thread safe behaviour and support for multiple SingleApplication instances
Problem raised by @retmas in #24
2017-04-23 14:31:32 +03:00
Itay Grudev
cf347c47af Refactored SingleApplicationPrivate destructor.
Deleted the separate cleanUp method as it’s not used from anywhere but
the destructor.
2017-01-30 17:47:01 +00:00
Svintsov Dmitry
ebcfabc3ae Added missing "QMutex" dependencies 2016-08-22 15:29:14 +05:00
Itay Grudev
4e5c1647cc
SingleApplication v3.0a 2016-08-10 03:41:03 +01:00