Skip to content

Commit

Permalink
fix(IPCConnection): add good bit field, resolves #2
Browse files Browse the repository at this point in the history
  • Loading branch information
unstabler committed Feb 4, 2023
1 parent 18701d8 commit 877b1cc
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 6 deletions.
16 changes: 15 additions & 1 deletion IPCConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ IPCConnection::IPCConnection(std::string socketPath):
_isWorkerTerminated(false),

_messageId(0),
_ackId(0)
_ackId(0),
_isGood(true)
{

}
Expand Down Expand Up @@ -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)));
}
Expand Down Expand Up @@ -87,6 +92,8 @@ void IPCConnection::workerLoop() {
0
};

_isGood = true;

while (!_isWorkerTerminated) {
if (poll(&pollFd, 1, -1) < 0) {
throw SystemCallException(errno, "poll");
Expand Down Expand Up @@ -138,6 +145,10 @@ void IPCConnection::workerLoop() {
}
}

if (_isGood && retval <= 0) {
break;
}

readPos += retval;

if (readPos >= contentLength) {
Expand All @@ -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");
Expand All @@ -166,4 +178,6 @@ void IPCConnection::workerLoop() {
break;
}
}

_isGood = false;
}
4 changes: 4 additions & 0 deletions IPCConnection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ class IPCConnection {
*/
void connect();
void disconnect();

bool isGood() const;

std::unique_ptr<ULIPCHeader, MallocFreeDeleter> nextHeader();

Expand Down Expand Up @@ -79,6 +81,8 @@ class IPCConnection {
UnixSocket _socket;
std::thread _workerThread;
bool _isWorkerTerminated;

bool _isGood;

std::mutex _writeTasksLock;
std::mutex _readTasksLock;
Expand Down
2 changes: 2 additions & 0 deletions ProjectionTarget.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ class ProjectionTarget {
size_t size,
int32_t width, int32_t height
) = 0;

virtual void ipcDisconnected() = 0;
};

#endif //ULALACA_PROJECTIONCONTEXT_HPP
10 changes: 8 additions & 2 deletions ProjectorClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion ProjectorClient.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class ProjectorClient {

private:
void mainLoop();

ProjectionTarget &_target;
IPCConnection _ipcConnection;

Expand Down
5 changes: 5 additions & 0 deletions XrdpUlalacaPrivate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
6 changes: 4 additions & 2 deletions XrdpUlalacaPrivate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,15 @@ class XrdpUlalacaPrivate: public ProjectionTarget {
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;
Expand Down
4 changes: 4 additions & 0 deletions XrdpUlalacaPrivate.xrdpmodule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit 877b1cc

Please sign in to comment.