IPCWorker.cpp 994 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #include "../IO/Log.h"
  2. #include "IPCWorker.h"
  3. #include "IPCMessage.h"
  4. #include "IPCUnix.h"
  5. #ifdef ATOMIC_PLATFORM_WINDOWS
  6. #else
  7. #include <unistd.h>
  8. #endif
  9. namespace Atomic
  10. {
  11. IPCWorker::IPCWorker(int fd, Context* context) : IPCChannel(context),
  12. fd_(fd)
  13. {
  14. otherProcess_ = new IPCProcess(context_, -1, fd, getppid());
  15. if (!transport_.OpenClient(fd_))
  16. {
  17. LOGERRORF("Unable to open IPC transport fd = %i", fd_);
  18. shouldRun_ = false;
  19. return;
  20. }
  21. LOGERRORF("Opened IPC transport fd = %i", fd_);
  22. }
  23. IPCWorker::~IPCWorker()
  24. {
  25. }
  26. bool IPCWorker::Update()
  27. {
  28. if (otherProcess_.Null())
  29. return false;
  30. if (!shouldRun_)
  31. {
  32. Stop();
  33. return false;
  34. }
  35. return true;
  36. }
  37. void IPCWorker::ThreadFunction()
  38. {
  39. while (shouldRun_)
  40. {
  41. if (!otherProcess_->IsRunning())
  42. {
  43. break;
  44. }
  45. if (!Receive())
  46. {
  47. break;
  48. }
  49. }
  50. shouldRun_ = false;
  51. }
  52. }