1 /* 2 * Copyright 2013 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 P2P_BASE_ASYNC_STUN_TCP_SOCKET_H_ 12 #define P2P_BASE_ASYNC_STUN_TCP_SOCKET_H_ 13 14 #include <stddef.h> 15 16 #include "rtc_base/async_packet_socket.h" 17 #include "rtc_base/async_tcp_socket.h" 18 #include "rtc_base/socket.h" 19 #include "rtc_base/socket_address.h" 20 21 namespace cricket { 22 23 class AsyncStunTCPSocket : public rtc::AsyncTCPSocketBase { 24 public: 25 // Binds and connects `socket` and creates AsyncTCPSocket for 26 // it. Takes ownership of `socket`. Returns NULL if bind() or 27 // connect() fail (`socket` is destroyed in that case). 28 static AsyncStunTCPSocket* Create(rtc::Socket* socket, 29 const rtc::SocketAddress& bind_address, 30 const rtc::SocketAddress& remote_address); 31 32 explicit AsyncStunTCPSocket(rtc::Socket* socket); 33 34 AsyncStunTCPSocket(const AsyncStunTCPSocket&) = delete; 35 AsyncStunTCPSocket& operator=(const AsyncStunTCPSocket&) = delete; 36 37 int Send(const void* pv, 38 size_t cb, 39 const rtc::PacketOptions& options) override; 40 void ProcessInput(char* data, size_t* len) override; 41 42 private: 43 // This method returns the message hdr + length written in the header. 44 // This method also returns the number of padding bytes needed/added to the 45 // turn message. `pad_bytes` should be used only when `is_turn` is true. 46 size_t GetExpectedLength(const void* data, size_t len, int* pad_bytes); 47 }; 48 49 } // namespace cricket 50 51 #endif // P2P_BASE_ASYNC_STUN_TCP_SOCKET_H_ 52