6#include "../AsyncSocketBase.hxx"
8#include "../ReTurnSubsystem.hxx"
10#define RESIPROCATE_SUBSYSTEM ReTurnSubsystem::RETURN
33 asio::error_code errorCode;
37 asio::error_code ignored;
38 socket.set_option(asio::ip::tcp::no_delay(
true), ignored);
39 socket.set_option(asio::ip::tcp::socket::reuse_address(
true), ignored);
48 bool timedOut =
false;
51 timer.async_wait([&timedOut, &cancel](
const asio::error_code& e)
61 while(result == asio::error::would_block &&
mIOService.run_one() > 0)
67 return timedOut ? asio::error_code(asio::error::timed_out) : result;
76 asio::error_code errorCode;
77 asio::ip::tcp::resolver::results_type results = resolver.resolve(
protocol(), address, service.
c_str(), errorCode);
82 asio::ip::tcp::resolver::results_type::const_iterator endpoint_iterator = results.begin();
83 asio::ip::tcp::resolver::results_type::const_iterator end = results.end();
87 errorCode = asio::error::host_not_found;
88 while (errorCode && endpoint_iterator != end)
94 asio::error_code result = asio::error::would_block;
95 mSocket.async_connect(*endpoint_iterator, [&result](
const asio::error_code& ec) { result = ec; });
96 errorCode =
waitForConnectStep(result, [
this]() { asio::error_code ignored; mSocket.close(ignored); });
115 asio::error_code errorCode;
116 asio::write(mSocket, asio::buffer(buffer, size), asio::transfer_all(), errorCode);
123 asio::error_code errorCode;
124 asio::write(mSocket, buffers, asio::transfer_all(), errorCode);
129TurnTcpSocket::rawRead(
unsigned int timeout,
unsigned int* bytesRead, asio::ip::address* sourceAddress,
unsigned short* sourcePort)
156 asio::async_read(mSocket, asio::buffer(
mReadBuffer, 4),
163 asio::async_read(mSocket, asio::buffer(&
mReadBuffer[4], len),
191 dataLen = ntohs(dataLen);
210 if (e != asio::error::operation_aborted)
212 WarningLog(<<
"Read header error: " << e.value() <<
"-" << e.message());
#define WarningLog(args_)
static size_t channelDataPadding(size_t length)
Over TCP and TLS, a TURN ChannelData message is padded to a multiple of 4 bytes, the padding not coun...
const asio::ip::address & getAddress() const
unsigned int getPort() const
void setPort(unsigned int port)
void setAddress(const asio::ip::address &address)
void setTransportType(TransportType transport)
void handleRawRead(const asio::error_code &errorCode, size_t bytesRead)
asio::io_context mIOService
asio::steady_timer mReadTimer
asio::error_code mReadErrorCode
void startReadTimer(unsigned int timeout)
StunTuple mConnectedTuple
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)
TurnTcpSocket(const asio::ip::address &address=UnspecifiedIpAddress, unsigned short port=0)
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()
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.
An alternative to std::string, encapsulates an arbitrary buffer of bytes.
const char * c_str() const
Returns a null-terminated string representing.