reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
TurnTcpSocket.hxx
Go to the documentation of this file.
1#ifndef TURNTCPSOCKET_HXX
2#define TURNTCPSOCKET_HXX
3
4#include <asio.hpp>
5#ifdef USE_SSL
6#include <asio/ssl.hpp>
7#endif
8#include <functional>
9
10#include "TurnSocket.hxx"
11
12namespace reTurn {
13
15{
16public:
17 explicit TurnTcpSocket(const asio::ip::address& address = UnspecifiedIpAddress,
18 unsigned short port = 0);
19
20 virtual unsigned int getSocketDescriptor() { return (unsigned int)mSocket.native_handle(); }
21
22 // To use this socket without a Turn Relay, use this connect call to connect directly
23 // to endpoint
24 virtual asio::error_code connect(const std::string& address, unsigned short port);
25
29
30protected:
31 virtual asio::error_code rawWrite(const char* buffer, unsigned int size);
32 virtual asio::error_code rawWrite(const std::vector<asio::const_buffer>& buffers);
33 virtual asio::error_code rawRead(unsigned int timeout, unsigned int* bytesRead, asio::ip::address* sourceAddress=0, unsigned short* sourcePort=0);
34
35 virtual void readHeader();
36 virtual void readBody(unsigned int len);
37 virtual void cancelSocket();
38
40 virtual void handleReadHeader(const asio::error_code& e);
41
45 asio::error_code openAndBind(asio::ip::tcp::socket& socket);
47 asio::ip::tcp protocol() const;
48
53 asio::error_code waitForConnectStep(asio::error_code& result, const std::function<void()>& cancel);
54 unsigned int mConnectTimeout = 10000;
55
56 size_t mPadding = 0; // after the ChannelData message being read
57
58private:
59
60 asio::ip::tcp::socket mSocket;
61};
62
63}
64
65#endif
66
67
68/* ====================================================================
69
70 Copyright (c) 2008-2026 SIP Spectrum, Inc. https://www.sipspectrum.com
71 Copyright (c) 2007-2008, Plantronics, Inc.
72 All rights reserved.
73
74 Redistribution and use in source and binary forms, with or without
75 modification, are permitted provided that the following conditions are
76 met:
77
78 1. Redistributions of source code must retain the above copyright
79 notice, this list of conditions and the following disclaimer.
80
81 2. Redistributions in binary form must reproduce the above copyright
82 notice, this list of conditions and the following disclaimer in the
83 documentation and/or other materials provided with the distribution.
84
85 3. Neither the name of Plantronics nor the names of its contributors
86 may be used to endorse or promote products derived from this
87 software without specific prior written permission.
88
89 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
90 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
91 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
92 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
93 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
94 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
95 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
96 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
97 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
98 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
99 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
100
101 ==================================================================== */
static asio::ip::address UnspecifiedIpAddress
asio::error_code waitForConnectStep(asio::error_code &result, const std::function< void()> &cancel)
For a step of connect() started as an asynchronous operation that sets result (initially asio::error:...
virtual asio::error_code connect(const std::string &address, unsigned short port)
virtual asio::error_code rawRead(unsigned int timeout, unsigned int *bytesRead, asio::ip::address *sourceAddress=0, unsigned short *sourcePort=0)
virtual unsigned int getSocketDescriptor()
virtual asio::error_code rawWrite(const char *buffer, unsigned int size)
virtual void readHeader()
virtual void readBody(unsigned int len)
virtual void handleReadHeader(const asio::error_code &e)
Handle completion of a read operation for first 32 bits.
unsigned int mConnectTimeout
asio::ip::tcp protocol() const
The protocol (IPv4 or IPv6) of the local binding.
virtual void cancelSocket()
void setConnectTimeout(unsigned int milliseconds)
Milliseconds the TCP connect to each address connect() tries may take - and, for TLS,...
asio::error_code openAndBind(asio::ip::tcp::socket &socket)
Opens socket and binds it to the local binding (address and port), for a connection attempt.
void list()
Definition userAdmin.cxx:66