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 11 #ifndef RTC_BASE_SOCKET_STREAM_H_ 12 #define RTC_BASE_SOCKET_STREAM_H_ 13 14 #include <stddef.h> 15 16 #include "rtc_base/socket.h" 17 #include "rtc_base/stream.h" 18 #include "rtc_base/third_party/sigslot/sigslot.h" 19 20 namespace rtc { 21 22 /////////////////////////////////////////////////////////////////////////////// 23 24 class SocketStream : public StreamInterface, public sigslot::has_slots<> { 25 public: 26 explicit SocketStream(Socket* socket); 27 ~SocketStream() override; 28 29 SocketStream(const SocketStream&) = delete; 30 SocketStream& operator=(const SocketStream&) = delete; 31 32 void Attach(Socket* socket); 33 Socket* Detach(); 34 GetSocket()35 Socket* GetSocket() { return socket_; } 36 37 StreamState GetState() const override; 38 39 StreamResult Read(rtc::ArrayView<uint8_t> buffer, 40 size_t& read, 41 int& error) override; 42 43 StreamResult Write(rtc::ArrayView<const uint8_t> data, 44 size_t& written, 45 int& error) override; 46 47 void Close() override; 48 49 private: 50 void OnConnectEvent(Socket* socket); 51 void OnReadEvent(Socket* socket); 52 void OnWriteEvent(Socket* socket); 53 void OnCloseEvent(Socket* socket, int err); 54 55 Socket* socket_; 56 }; 57 58 /////////////////////////////////////////////////////////////////////////////// 59 60 } // namespace rtc 61 62 #endif // RTC_BASE_SOCKET_STREAM_H_ 63