blob: 2c43d554fe5fb3270776d8c1a6e1bab9923e1081 [file] [log] [blame]
henrike@webrtc.org269fb4b2014-10-28 22:20:111/*
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 17:11:0011#ifndef P2P_BASE_ASYNC_STUN_TCP_SOCKET_H_
12#define P2P_BASE_ASYNC_STUN_TCP_SOCKET_H_
henrike@webrtc.org269fb4b2014-10-28 22:20:1113
Yves Gerey3e707812018-11-28 15:47:4914#include <stddef.h>
15
Steve Anton10542f22019-01-11 17:11:0016#include "rtc_base/async_packet_socket.h"
Steve Anton10542f22019-01-11 17:11:0017#include "rtc_base/async_tcp_socket.h"
Niels Möllerd0b88792021-08-12 08:32:3018#include "rtc_base/socket.h"
Steve Anton10542f22019-01-11 17:11:0019#include "rtc_base/socket_address.h"
henrike@webrtc.org269fb4b2014-10-28 22:20:1120
21namespace cricket {
22
23class AsyncStunTCPSocket : public rtc::AsyncTCPSocketBase {
24 public:
Artem Titov2dbb4c92021-07-26 13:12:4125 // 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).
Niels Möllerd0b88792021-08-12 08:32:3028 static AsyncStunTCPSocket* Create(rtc::Socket* socket,
Yves Gerey665174f2018-06-19 13:03:0529 const rtc::SocketAddress& bind_address,
30 const rtc::SocketAddress& remote_address);
henrike@webrtc.org269fb4b2014-10-28 22:20:1131
Niels Möller6da016f2021-09-17 14:27:5632 explicit AsyncStunTCPSocket(rtc::Socket* socket);
henrike@webrtc.org269fb4b2014-10-28 22:20:1133
Byoungchan Leec065e732022-01-18 00:35:4834 AsyncStunTCPSocket(const AsyncStunTCPSocket&) = delete;
35 AsyncStunTCPSocket& operator=(const AsyncStunTCPSocket&) = delete;
36
Steve Antonf2737d22017-10-31 23:27:3437 int Send(const void* pv,
38 size_t cb,
39 const rtc::PacketOptions& options) override;
Per K357947f2023-11-27 12:03:5240 size_t ProcessInput(rtc::ArrayView<const uint8_t> data) override;
henrike@webrtc.org269fb4b2014-10-28 22:20:1141
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
Artem Titov2dbb4c92021-07-26 13:12:4145 // turn message. `pad_bytes` should be used only when `is_turn` is true.
Yves Gerey665174f2018-06-19 13:03:0546 size_t GetExpectedLength(const void* data, size_t len, int* pad_bytes);
henrike@webrtc.org269fb4b2014-10-28 22:20:1147};
48
49} // namespace cricket
50
Steve Anton10542f22019-01-11 17:11:0051#endif // P2P_BASE_ASYNC_STUN_TCP_SOCKET_H_