blob: a299e61145075e557230470638d788b3266ea449 [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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef P2P_BASE_ASYNCSTUNTCPSOCKET_H_
12#define P2P_BASE_ASYNCSTUNTCPSOCKET_H_
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000013
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020014#include "rtc_base/asynctcpsocket.h"
15#include "rtc_base/constructormagic.h"
16#include "rtc_base/socketfactory.h"
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000017
18namespace cricket {
19
20class AsyncStunTCPSocket : public rtc::AsyncTCPSocketBase {
21 public:
22 // Binds and connects |socket| and creates AsyncTCPSocket for
23 // it. Takes ownership of |socket|. Returns NULL if bind() or
24 // connect() fail (|socket| is destroyed in that case).
Yves Gerey665174f2018-06-19 15:03:05 +020025 static AsyncStunTCPSocket* Create(rtc::AsyncSocket* socket,
26 const rtc::SocketAddress& bind_address,
27 const rtc::SocketAddress& remote_address);
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000028
29 AsyncStunTCPSocket(rtc::AsyncSocket* socket, bool listen);
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000030
Steve Antonf2737d22017-10-31 16:27:34 -070031 int Send(const void* pv,
32 size_t cb,
33 const rtc::PacketOptions& options) override;
34 void ProcessInput(char* data, size_t* len) override;
35 void HandleIncomingConnection(rtc::AsyncSocket* socket) override;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000036
37 private:
38 // This method returns the message hdr + length written in the header.
39 // This method also returns the number of padding bytes needed/added to the
40 // turn message. |pad_bytes| should be used only when |is_turn| is true.
Yves Gerey665174f2018-06-19 15:03:05 +020041 size_t GetExpectedLength(const void* data, size_t len, int* pad_bytes);
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000042
henrikg3c089d72015-09-16 05:37:44 -070043 RTC_DISALLOW_COPY_AND_ASSIGN(AsyncStunTCPSocket);
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000044};
45
46} // namespace cricket
47
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020048#endif // P2P_BASE_ASYNCSTUNTCPSOCKET_H_