socket.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // Copyright 2019 Google LLC
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // https://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #ifndef dap_socket_h
  15. #define dap_socket_h
  16. #include "dap/io.h"
  17. #include <atomic>
  18. #include <memory>
  19. namespace dap {
  20. class Socket {
  21. public:
  22. class Shared;
  23. // connect() connects to the given TCP address and port.
  24. // If timeoutMillis is non-zero and no connection was made before
  25. // timeoutMillis milliseconds, then nullptr is returned.
  26. static std::shared_ptr<ReaderWriter> connect(const char* address,
  27. const char* port,
  28. uint32_t timeoutMillis);
  29. Socket(const char* address, const char* port);
  30. bool isOpen() const;
  31. std::shared_ptr<ReaderWriter> accept() const;
  32. void close() const;
  33. private:
  34. std::shared_ptr<Shared> shared;
  35. };
  36. } // namespace dap
  37. #endif // dap_socket_h