blob: 0f190be4b2aa22b8d6ff2d4e554d92690a93e58a [file] [log] [blame]
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +00001/*
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
Steve Anton10542f22019-01-11 09:11:00 -080011#ifndef P2P_BASE_ASYNC_STUN_TCP_SOCKET_H_
12#define P2P_BASE_ASYNC_STUN_TCP_SOCKET_H_
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000013
Yves Gerey3e707812018-11-28 16:47:49 +010014#include <stddef.h>
15
Steve Anton10542f22019-01-11 09:11:00 -080016#include "rtc_base/async_packet_socket.h"
17#include "rtc_base/async_socket.h"
18#include "rtc_base/async_tcp_socket.h"
19#include "rtc_base/constructor_magic.h"
20#include "rtc_base/socket_address.h"
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000021
22namespace cricket {
23
24class AsyncStunTCPSocket : public rtc::AsyncTCPSocketBase {
25 public:
26 // Binds and connects |socket| and creates AsyncTCPSocket for
27 // it. Takes ownership of |socket|. Returns NULL if bind() or
28 // connect() fail (|socket| is destroyed in that case).
Yves Gerey665174f2018-06-19 15:03:05 +020029 static AsyncStunTCPSocket* Create(rtc::AsyncSocket* socket,
30 const rtc::SocketAddress& bind_address,
31 const rtc::SocketAddress& remote_address);
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000032
33 AsyncStunTCPSocket(rtc::AsyncSocket* socket, bool listen);
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000034
Steve Antonf2737d22017-10-31 16:27:34 -070035 int Send(const void* pv,
36 size_t cb,
37 const rtc::PacketOptions& options) override;
38 void ProcessInput(char* data, size_t* len) override;
39 void HandleIncomingConnection(rtc::AsyncSocket* socket) override;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000040
41 private:
42 // This method returns the message hdr + length written in the header.
43 // This method also returns the number of padding bytes needed/added to the
44 // turn message. |pad_bytes| should be used only when |is_turn| is true.
Yves Gerey665174f2018-06-19 15:03:05 +020045 size_t GetExpectedLength(const void* data, size_t len, int* pad_bytes);
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000046
henrikg3c089d72015-09-16 05:37:44 -070047 RTC_DISALLOW_COPY_AND_ASSIGN(AsyncStunTCPSocket);
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000048};
49
50} // namespace cricket
51
Steve Anton10542f22019-01-11 09:11:00 -080052#endif // P2P_BASE_ASYNC_STUN_TCP_SOCKET_H_