async_stun_tcp_socket.h 1.9 KB

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