IPCWorker.cpp 1.1 KB

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