henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef P2P_BASE_ASYNCSTUNTCPSOCKET_H_ |
| 12 | #define P2P_BASE_ASYNCSTUNTCPSOCKET_H_ |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 13 | |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 14 | #include <stddef.h> |
| 15 | |
| 16 | #include "rtc_base/asyncpacketsocket.h" |
| 17 | #include "rtc_base/asyncsocket.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 18 | #include "rtc_base/asynctcpsocket.h" |
| 19 | #include "rtc_base/constructormagic.h" |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 20 | #include "rtc_base/socketaddress.h" |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 21 | |
| 22 | namespace cricket { |
| 23 | |
| 24 | class 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 Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 29 | static AsyncStunTCPSocket* Create(rtc::AsyncSocket* socket, |
| 30 | const rtc::SocketAddress& bind_address, |
| 31 | const rtc::SocketAddress& remote_address); |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 32 | |
| 33 | AsyncStunTCPSocket(rtc::AsyncSocket* socket, bool listen); |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 34 | |
Steve Anton | f2737d2 | 2017-10-31 16:27:34 -0700 | [diff] [blame] | 35 | 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.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 40 | |
| 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 Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 45 | size_t GetExpectedLength(const void* data, size_t len, int* pad_bytes); |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 46 | |
henrikg | 3c089d7 | 2015-09-16 05:37:44 -0700 | [diff] [blame] | 47 | RTC_DISALLOW_COPY_AND_ASSIGN(AsyncStunTCPSocket); |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 48 | }; |
| 49 | |
| 50 | } // namespace cricket |
| 51 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 52 | #endif // P2P_BASE_ASYNCSTUNTCPSOCKET_H_ |