Commit Graph

46 Commits

Author SHA1 Message Date
Christoph Cullmann
611e48abbb
Provide API for blocking sendMessage (#154) 2022-04-05 23:46:42 +03:00
Christoph Cullmann
ee17b253d3 make it compile with Qt 6.2.x and stricter compile settings 2022-04-03 19:45:03 +02:00
Moody
a0917f9c62
fix deprecated warnings on Qt6.3+ 2022-02-13 11:16:05 +00:00
Nicolas Werner
3650975e56
Fix crash when sending ack on removed connection
The emit might interrupt our function and causes us to return to the
event loop. In that time frame the other and might close the connection,
causing our connection to be removed. In that case we call writeAck on a
dangling pointer, in the best case causing a crash. So lets finish our
business before emitting our signal.

fixes #138
2021-11-24 09:01:39 +01:00
Itay Grudev
9856adebd4
Update singleapplication_p.cpp 2021-09-20 16:38:28 +03:00
Itay Grudev
bca0b770ee
Update singleapplication_p.cpp
Co-authored-by: Hennadii Chernyshchyk <genaloner@gmail.com>
2021-09-20 16:37:01 +03:00
Itay Grudev
cc96fea921
Update singleapplication_p.cpp 2021-09-20 16:32:42 +03:00
Itay Grudev
6aa2d348e5
Style and explanation improvements 2021-09-20 16:22:02 +03:00
Michael Klein
a30128bef2
Compile fix
Co-authored-by: Hennadii Chernyshchyk <genaloner@gmail.com>
2021-09-20 15:16:20 +02:00
Michael Klein
7d366c7e83
Use QByteArray instead of QString
Co-authored-by: Hennadii Chernyshchyk <genaloner@gmail.com>
2021-09-20 14:56:31 +02:00
Michael Klein
f030b378f0 Use AppImage path for hash when running as AppImage.
When an application is launched as AppImage, each instance is launched
from its own FUSE-mounted filesystem, so each instance has its own
executable path.

The AppImage runtime sets the environment variable APPIMAGE to the
absolute path to the .AppImage file, so we can use the content of this
variable instead of QApplication::applicationFilePath() when set.

Closes #77, #137
2021-09-20 14:43:15 +02:00
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
Shatur95
c2fd401540 Simplify randomSleep() for old Qt version 2021-04-12 14:17:53 +03:00
Jonas Kvinge
4052d37110 Fix signal-slot issues 2021-03-26 00:16:25 +01:00
dail8859
5e7b302776
Update singleapplication_p.cpp
Co-authored-by: Hennadii Chernyshchyk <genaloner@gmail.com>
2020-12-23 15:42:56 -05:00
dail8859
99cd51d5a2 Remove ConnectionInfo after socket is destroyed
This leaves the ConnectionInfo in a valid state, even after the socket is disconnected, which could still have a readyRead() signal emitted.

Closes #123
2020-12-22 21:03:10 -05:00
Loren Burkholder
f236032cf9 Allow adding unique userdata to instances 2020-12-16 22:17:24 -05:00
Itay Grudev
a627bc24fa
Merge pull request #114 from Shatur95/fix-clang-tidy-warnings
Fix Clang Tidy warnings
2020-10-18 09:44:21 +01:00
Jonas Kvinge
b5e6e2ba75 Fix use of qChecksum with Qt 6 2020-10-18 00:58:52 +02:00
Shatur95
199defc4dd Remove unused marco
No longer needed since applicationPid() now is static.
2020-10-15 23:06:50 +03: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
Shatur95
a8fb6b49f5 Fix implicit conversion 2020-10-15 01:29:25 +03:00
Shatur95
fae8a8a65f Fix conversion from int to quint32 2020-10-10 20:31:47 +03:00
iakov
800bb858a8
Fix build issue with MinGW GCC pedantic mode
Without guard this define from 3230430311 (diff-35c7c4188004bde084344a3aa8eeab6dR60) introduced compilation warning/error, and can break compilation
2020-10-06 13:56:20 +03:00
Jonas Kvinge
a121f61ca1 Fix return value of connectToPrimary() when connect is successful 2020-10-05 22:13:03 +02:00
Nick Korotysh
3230430311
fixed build with Qt 5.9 MSVC2017
define NOMINMAX before <Windows.h> inclusion to disable min/max macros
defined in it. these macros conflict with any min/max functions and it
is common practice to disable them adding NOMINMAX define.
2020-10-02 14:17:34 +03:00
Itay Grudev
ca8e9aaa9e Removed debugging information for the instanceStarted signal 2020-09-09 02:30:43 +01: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
fb9c0bd2ef Removed extra qDebug statements 2020-09-09 00:48:55 +01:00
Itay Grudev
e4282f2476 Mitigated possible race condition during app startup 2020-09-09 00:28:02 +01:00
Shatur95
c5042727ae Use qstrncpy
Fixes MSVC C4996 warning.
2020-07-02 02:36:54 +03:00
Shatur95
fcd4fcab21 Fix Clang Tidy warnings 2020-05-17 17:50:27 +03:00
Itay Grudev
f31880dc7f
Update singleapplication_p.cpp 2020-04-22 00:58:15 +01:00
Emeric
b4a1f19d81 Fix a crash when exiting an application on Android and iOS 2020-04-20 18:33:30 +02:00
Leander Schulten
00a2530465 Add support for Qt < 5.10 2020-03-27 08:24:43 +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
iakov
196bb34af6 Fix compilation warning/error (#74)
Fix `comparison between signed and unsigned integer expressions` problem.
User ID is a positive integer  in Linux/UNIX(macOS, FreeBSD, Solaris), also `geteuid()` never fails with return code.
2019-10-10 14:47:25 +03:00
Jonas Kvinge
2c959069b7 Use geteuid and getpwuid to get username on Unix, fallback to environment variable (#72)
* Use geteuid and getpwuid to get username on Unix, fallback to environment variable

* Remove QProcess include
2019-09-22 20:39:45 +03:00
Itay Grudev
adac9a30aa
v3.0.14 2019-01-22 12:23:51 +00:00
Patrizio Bekerle
b24d5394a5 fixed build process below Qt 5.6 (#57) 2018-12-14 20:41:55 +02: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