Server.hpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. ///
  2. /// \file Remote/Server.hpp
  3. ///
  4. /// Remote access proxy server interface.
  5. ///
  6. /// \copyright
  7. /// Copyright (c) 2013-2016 Josh Blum
  8. /// SPDX-License-Identifier: BSL-1.0
  9. ///
  10. #pragma once
  11. #include <Pothos/Config.hpp>
  12. #include <Pothos/Util/RefHolder.hpp>
  13. #include <memory>
  14. #include <string>
  15. namespace Pothos {
  16. /*!
  17. * A remote server is a handle for an executing server process.
  18. * When all copies of the handle destruct, the server process will be terminated.
  19. */
  20. class POTHOS_API RemoteServer : public Util::RefHolder
  21. {
  22. public:
  23. //! Make an empty handle
  24. RemoteServer(void);
  25. /*!
  26. * Spawn a new process on this machine, that is running a proxy server on the given URI.
  27. * URI format: tcp://resolvable_hostname:optional_port
  28. * A host address of 0.0.0.0 or [::] will bind the server to all interfaces.
  29. * An unspecified port means that an available port will be automatically chosen.
  30. * \param uri a formatted string which tells the server what kind of service to run
  31. * \param closePipes true to close stdout/err pipes (keep open for syslog forwarding)
  32. * \return a handle that when deleted, will cause the server/process to exit
  33. */
  34. RemoteServer(const std::string &uri, const bool closePipes = true);
  35. //! Get the server's bind URI
  36. const std::string &getUri(void) const;
  37. //! Is this remove server active?
  38. explicit operator bool(void) const;
  39. /*!
  40. * The locator port is the default port for running and locating a remote server.
  41. * Servers running on this part are used to establish initial communication.
  42. * Further communication can continue on arbitrary ports selected by the OS.
  43. */
  44. static std::string getLocatorPort(void);
  45. //! Get the actual port that the server is running on
  46. std::string getActualPort(void) const;
  47. /*!
  48. * Start syslog forwarding to the given address.
  49. * Spawn threads to read the stdout/err pipes from
  50. * the server process and forward to a syslog channel.
  51. * Only use when the server is created with closePipes false.
  52. * \param addr the log destination in host:port format
  53. * \param source the repoted source of the log messages
  54. */
  55. void startSyslogForwarding(const std::string &addr, const std::string &source);
  56. private:
  57. struct Impl;
  58. std::shared_ptr<Impl> _impl;
  59. };
  60. } //namespace Pothos