henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 | [diff] [blame] | 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 | |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 11 | #ifndef P2P_BASE_ASYNC_STUN_TCP_SOCKET_H_ |
| 12 | #define P2P_BASE_ASYNC_STUN_TCP_SOCKET_H_ |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 | [diff] [blame] | 13 | |
Yves Gerey | 3e70781 | 2018-11-28 15:47:49 | [diff] [blame] | 14 | #include <stddef.h> |
| 15 | |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 16 | #include "rtc_base/async_packet_socket.h" |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 17 | #include "rtc_base/async_tcp_socket.h" |
Niels Möller | d0b8879 | 2021-08-12 08:32:30 | [diff] [blame] | 18 | #include "rtc_base/socket.h" |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 19 | #include "rtc_base/socket_address.h" |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 | [diff] [blame] | 20 | |
| 21 | namespace cricket { |
| 22 | |
| 23 | class AsyncStunTCPSocket : public rtc::AsyncTCPSocketBase { |
| 24 | public: |
Artem Titov | 2dbb4c9 | 2021-07-26 13:12:41 | [diff] [blame] | 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). |
Niels Möller | d0b8879 | 2021-08-12 08:32:30 | [diff] [blame] | 28 | static AsyncStunTCPSocket* Create(rtc::Socket* socket, |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 29 | const rtc::SocketAddress& bind_address, |
| 30 | const rtc::SocketAddress& remote_address); |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 | [diff] [blame] | 31 | |
Niels Möller | 6da016f | 2021-09-17 14:27:56 | [diff] [blame] | 32 | explicit AsyncStunTCPSocket(rtc::Socket* socket); |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 | [diff] [blame] | 33 | |
Byoungchan Lee | c065e73 | 2022-01-18 00:35:48 | [diff] [blame] | 34 | AsyncStunTCPSocket(const AsyncStunTCPSocket&) = delete; |
| 35 | AsyncStunTCPSocket& operator=(const AsyncStunTCPSocket&) = delete; |
| 36 | |
Steve Anton | f2737d2 | 2017-10-31 23:27:34 | [diff] [blame] | 37 | int Send(const void* pv, |
| 38 | size_t cb, |
| 39 | const rtc::PacketOptions& options) override; |
Per K | 357947f | 2023-11-27 12:03:52 | [diff] [blame] | 40 | size_t ProcessInput(rtc::ArrayView<const uint8_t> data) override; |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 | [diff] [blame] | 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 |
Artem Titov | 2dbb4c9 | 2021-07-26 13:12:41 | [diff] [blame] | 45 | // turn message. `pad_bytes` should be used only when `is_turn` is true. |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 46 | size_t GetExpectedLength(const void* data, size_t len, int* pad_bytes); |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 | [diff] [blame] | 47 | }; |
| 48 | |
| 49 | } // namespace cricket |
| 50 | |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 51 | #endif // P2P_BASE_ASYNC_STUN_TCP_SOCKET_H_ |