diff options
author | Gyuhwan Park★ <unstabler@unstabler.pl> | 2023-02-04 12:43:43 +0300 |
---|---|---|
committer | Gyuhwan Park★ <unstabler@unstabler.pl> | 2023-02-04 12:43:43 +0300 |
commit | 877b1cca50a2eb9670e901525ad6d83803adfd68 (patch) | |
tree | 3d1aea7e107d69515ffc33cf932f6aac44595dc5 | |
parent | 18701d80d5590748d6a27561e7d90e0e7a7a1534 (diff) |
fix(IPCConnection): add good bit field, resolves #2
-rw-r--r-- | IPCConnection.cpp | 16 | ||||
-rw-r--r-- | IPCConnection.hpp | 4 | ||||
-rw-r--r-- | ProjectionTarget.hpp | 2 | ||||
-rw-r--r-- | ProjectorClient.cpp | 10 | ||||
-rw-r--r-- | ProjectorClient.hpp | 2 | ||||
-rw-r--r-- | XrdpUlalacaPrivate.cpp | 5 | ||||
-rw-r--r-- | XrdpUlalacaPrivate.hpp | 6 | ||||
-rw-r--r-- | XrdpUlalacaPrivate.xrdpmodule.cpp | 4 |
8 files changed, 43 insertions, 6 deletions
diff --git a/IPCConnection.cpp b/IPCConnection.cpp index c23fd36..6b49da4 100644 --- a/IPCConnection.cpp +++ b/IPCConnection.cpp @@ -23,7 +23,8 @@ IPCConnection::IPCConnection(std::string socketPath): _isWorkerTerminated(false), _messageId(0), - _ackId(0) + _ackId(0), + _isGood(true) { } @@ -54,6 +55,10 @@ void IPCConnection::disconnect() { _socket.close(); } +bool IPCConnection::isGood() const { + return _isGood; +} + std::unique_ptr<ULIPCHeader, IPCConnection::MallocFreeDeleter> IPCConnection::nextHeader() { return std::move(read<ULIPCHeader>(sizeof(ULIPCHeader))); } @@ -87,6 +92,8 @@ void IPCConnection::workerLoop() { 0 }; + _isGood = true; + while (!_isWorkerTerminated) { if (poll(&pollFd, 1, -1) < 0) { throw SystemCallException(errno, "poll"); @@ -138,6 +145,10 @@ void IPCConnection::workerLoop() { } } + if (_isGood && retval <= 0) { + break; + } + readPos += retval; if (readPos >= contentLength) { @@ -154,6 +165,7 @@ void IPCConnection::workerLoop() { if (pollFd.revents & POLLHUP) { LOG(LOG_LEVEL_WARNING, "POLLHUP bit set"); + _isGood = false; if (_readTasks.empty()) { LOG(LOG_LEVEL_WARNING, "POLLHUP bit set; closing connection"); @@ -166,4 +178,6 @@ void IPCConnection::workerLoop() { break; } } + + _isGood = false; } diff --git a/IPCConnection.hpp b/IPCConnection.hpp index 10d0553..62e43d5 100644 --- a/IPCConnection.hpp +++ b/IPCConnection.hpp @@ -31,6 +31,8 @@ public: */ void connect(); void disconnect(); + + bool isGood() const; std::unique_ptr<ULIPCHeader, MallocFreeDeleter> nextHeader(); @@ -79,6 +81,8 @@ private: UnixSocket _socket; std::thread _workerThread; bool _isWorkerTerminated; + + bool _isGood; std::mutex _writeTasksLock; std::mutex _readTasksLock; diff --git a/ProjectionTarget.hpp b/ProjectionTarget.hpp index ef2d3ef..db242e7 100644 --- a/ProjectionTarget.hpp +++ b/ProjectionTarget.hpp @@ -19,6 +19,8 @@ public: size_t size, int32_t width, int32_t height ) = 0; + + virtual void ipcDisconnected() = 0; }; #endif //ULALACA_PROJECTIONCONTEXT_HPP diff --git a/ProjectorClient.cpp b/ProjectorClient.cpp index c57e87e..f6dcf18 100644 --- a/ProjectorClient.cpp +++ b/ProjectorClient.cpp @@ -52,7 +52,13 @@ void ProjectorClient::handleEvent(XrdpEvent &event) { if (_isTerminated) { return; } - + + if (!_ipcConnection.isGood()) { + _target.ipcDisconnected(); + this->stop(); + return; + } + if (event.isKeyEvent()) { auto keycode = event.param3; auto cgKeycode = rdpKeycodeToCGKeycode(keycode); @@ -176,7 +182,7 @@ void ProjectorClient::setOutputSuppression(bool isOutputSuppressed) { } void ProjectorClient::mainLoop() { - while (!_isTerminated) { + while (!_isTerminated && _ipcConnection.isGood()) { auto header = _ipcConnection.nextHeader(); switch (header->messageType) { diff --git a/ProjectorClient.hpp b/ProjectorClient.hpp index 7191533..f28f31f 100644 --- a/ProjectorClient.hpp +++ b/ProjectorClient.hpp @@ -38,7 +38,7 @@ public: private: void mainLoop(); - + ProjectionTarget &_target; IPCConnection _ipcConnection; diff --git a/XrdpUlalacaPrivate.cpp b/XrdpUlalacaPrivate.cpp index cd3c54b..117c4b5 100644 --- a/XrdpUlalacaPrivate.cpp +++ b/XrdpUlalacaPrivate.cpp @@ -144,6 +144,11 @@ void XrdpUlalacaPrivate::commitUpdate(const uint8_t *image, size_t size, int32_t }); } +void XrdpUlalacaPrivate::ipcDisconnected() { + LOG(LOG_LEVEL_WARNING, "ipc disconnected"); + _error = 1; +} + void XrdpUlalacaPrivate::updateThreadLoop() { while (_isUpdateThreadRunning) { while (_updateQueue.empty()) { diff --git a/XrdpUlalacaPrivate.hpp b/XrdpUlalacaPrivate.hpp index 98f9866..50f60ba 100644 --- a/XrdpUlalacaPrivate.hpp +++ b/XrdpUlalacaPrivate.hpp @@ -79,13 +79,15 @@ public: inline int decideCopyRectSize() const; inline std::unique_ptr<std::vector<ULIPCRect>> createCopyRects(std::vector<ULIPCRect> &dirtyRects, int rectSize) const; - void addDirtyRect(ULIPCRect &rect); - void commitUpdate(const uint8_t *image, size_t size, int32_t width, int32_t height); + void addDirtyRect(ULIPCRect &rect) override; + void commitUpdate(const uint8_t *image, size_t size, int32_t width, int32_t height) override; + void ipcDisconnected() override; void updateThreadLoop(); void calculateSessionSize(); + inline bool isNSCodec() const; inline bool isRFXCodec() const; inline bool isJPEGCodec() const; inline bool isH264Codec() const; diff --git a/XrdpUlalacaPrivate.xrdpmodule.cpp b/XrdpUlalacaPrivate.xrdpmodule.cpp index 654cc4a..448e6f8 100644 --- a/XrdpUlalacaPrivate.xrdpmodule.cpp +++ b/XrdpUlalacaPrivate.xrdpmodule.cpp @@ -118,6 +118,10 @@ int XrdpUlalacaPrivate::libModGetWaitObjs(tbus *readObjs, int *rcount, tbus *wri return 0; } + if (_error != 0) { + return 1; + } + readObjs[(*rcount)++] = _projectorClient->descriptor(); writeObjs[(*wcount)++] = _projectorClient->descriptor(); |