IPCWindows.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #ifdef ATOMIC_PLATFORM_WINDOWS
  2. #pragma once
  3. #include "../Core/Object.h"
  4. #include "IPCTypes.h"
  5. namespace Atomic
  6. {
  7. class PipePair {
  8. public:
  9. PipePair(bool inherit_fd2 = true);
  10. IPCHandle fd1() const { return srv_; }
  11. IPCHandle fd2() const { return cln_; }
  12. static IPCHandle OpenPipeServer(const wchar_t* name, bool low_integrity = true);
  13. static IPCHandle OpenPipeClient(const wchar_t* name, bool inherit, bool impersonate);
  14. private:
  15. IPCHandle srv_;
  16. IPCHandle cln_;
  17. };
  18. class PipeWin {
  19. public:
  20. PipeWin();
  21. ~PipeWin();
  22. bool OpenClient(IPCHandle pipe);
  23. bool OpenServer(IPCHandle pipe, bool connect = false);
  24. bool Write(const void* buf, size_t sz);
  25. bool Read(void* buf, size_t* sz);
  26. bool IsConnected() const { return pipe_ != INVALID_IPCHANDLE_VALUE; }
  27. private:
  28. IPCHandle pipe_;
  29. };
  30. class PipeTransport : public PipeWin {
  31. public:
  32. static const size_t kBufferSz = 4096;
  33. bool Send(const void* buf, size_t sz) {
  34. return Write(buf, sz);
  35. }
  36. char* Receive(size_t* size);
  37. private:
  38. PODVector<char> buf_;
  39. };
  40. class IPCProcess : public Object
  41. {
  42. OBJECT(IPCProcess)
  43. public:
  44. IPCProcess(Context* context, IPCHandle fd1, IPCHandle fd2, IPCHandle pid = INVALID_IPCHANDLE_VALUE);
  45. virtual ~IPCProcess();
  46. bool IsRunning();
  47. IPCHandle fd1() const { return fd1_; }
  48. IPCHandle fd2() const { return fd2_; }
  49. bool Launch(const String& command, const Vector<String>& args, const String& initialDirectory);
  50. private:
  51. IPCHandle pid_;
  52. IPCHandle fd1_;
  53. IPCHandle fd2_;
  54. };
  55. }
  56. #endif