socket_stream.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * Copyright 2005 The WebRTC Project Authors. All rights reserved.
  3. *
  4. * Use of this source code is governed by a BSD-style license
  5. * that can be found in the LICENSE file in the root of the source
  6. * tree. An additional intellectual property rights grant can be found
  7. * in the file PATENTS. All contributing project authors may
  8. * be found in the AUTHORS file in the root of the source tree.
  9. */
  10. #ifndef RTC_BASE_SOCKET_STREAM_H_
  11. #define RTC_BASE_SOCKET_STREAM_H_
  12. #include <stddef.h>
  13. #include "rtc_base/async_socket.h"
  14. #include "rtc_base/constructor_magic.h"
  15. #include "rtc_base/stream.h"
  16. #include "rtc_base/third_party/sigslot/sigslot.h"
  17. namespace rtc {
  18. ///////////////////////////////////////////////////////////////////////////////
  19. class SocketStream : public StreamInterface, public sigslot::has_slots<> {
  20. public:
  21. explicit SocketStream(AsyncSocket* socket);
  22. ~SocketStream() override;
  23. void Attach(AsyncSocket* socket);
  24. AsyncSocket* Detach();
  25. AsyncSocket* GetSocket() { return socket_; }
  26. StreamState GetState() const override;
  27. StreamResult Read(void* buffer,
  28. size_t buffer_len,
  29. size_t* read,
  30. int* error) override;
  31. StreamResult Write(const void* data,
  32. size_t data_len,
  33. size_t* written,
  34. int* error) override;
  35. void Close() override;
  36. private:
  37. void OnConnectEvent(AsyncSocket* socket);
  38. void OnReadEvent(AsyncSocket* socket);
  39. void OnWriteEvent(AsyncSocket* socket);
  40. void OnCloseEvent(AsyncSocket* socket, int err);
  41. AsyncSocket* socket_;
  42. RTC_DISALLOW_COPY_AND_ASSIGN(SocketStream);
  43. };
  44. ///////////////////////////////////////////////////////////////////////////////
  45. } // namespace rtc
  46. #endif // RTC_BASE_SOCKET_STREAM_H_