1#if defined(HAVE_CONFIG_H)
14#define RESIPROCATE_SUBSYSTEM Subsystem::TRANSPORT
25 const Data& pinterface,
28 unsigned transportFlags,
30 :
InternalTransport(fifo, portNum, version, pinterface, socketFunc, compression, transportFlags, netNs)
35 DebugLog(<<
"TcpBaseTransport: " <<
this <<
" netns: " <<
netNs);
81 if (::setsockopt(
mFd, SOL_SOCKET, SO_REUSEPORT, &on,
sizeof(on)))
86 throw Exception(
"Failed setsockopt", __FILE__, __LINE__);
89 if ( ::setsockopt (
mFd, SOL_SOCKET, SO_REUSEADDR, &on,
sizeof(on)) )
91 if ( ::setsockopt (
mFd, SOL_SOCKET, SO_REUSEADDR, (
const char*)&on,
sizeof(on)) )
97 throw Exception(
"Failed setsockopt", __FILE__,__LINE__);
106 int e = listen(
mFd,64 );
167 socklen_t peerLen = tuple.
length();
168 Socket sock = accept(
mFd, &peer, &peerLen);
175#if EAGAIN != EWOULDBLOCK
189 throw Exception(
"Failed to configure connected socket", __FILE__,__LINE__);
193 DebugLog (<<
this <<
" Received TCP connection from: " << tuple <<
" mTuple: " <<
mTuple <<
" as fd=" << sock);
204 InfoLog( <<
"Have client connection for " << tuple <<
", but got server one, recreate connection" );
210 InfoLog(<<
"Someone probably sent a reciprocal SYN at us.");
219TcpBaseTransport::bindClientSocket(
Socket sock,
223 sockaddr *sa =
reinterpret_cast<sockaddr*
>(_sa);
235 if (::setsockopt(sock, SOL_SOCKET, SO_REUSEPORT, &on,
sizeof(on)))
240 if (::setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &on,
sizeof(on)))
242 if (::setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (
const char*)&on,
sizeof(on)))
253 DebugLog(<<
"Symmetric connections mode: binding client socket to " <<
mTuple);
260 DebugLog(<<
"Default mode: binding client socket with ephemeral port: " <<
mTuple);
264 NetNs::setNs(
netNs());
284 NetNs::setNs(
netNs());
296 mConnectionManager.gcWithTarget(1);
300 NetNs::setNs(
netNs());
316 DebugLog (<<
"Opening new connection to " << dest);
320 if (!bindClientSocket(sock, failReason, failSubCode))
328 throw Exception(
"Failed to configure connected socket", __FILE__,__LINE__);
333 int ret = connect( sock, &servaddr, dest.
length() );
344#if EAGAIN != EWOULDBLOCK
351 InfoLog( <<
"Error on TCP connect to " << dest <<
", err=" << err <<
": " <<
strError(err));
471 mConnectionManager.
process(fdSet);
#define WarningLog(args_)
#define resip_assert(x)
This file needs to work for both C and C++ code.
Handles cross-platform sockets compatibility.
#define RESIP_TRANSPORT_FLAG_SYMMETRIC_CONNECTIONS
#define RESIP_TRANSPORT_FLAG_NOBIND
TransportFlags is bit-mask that can be set when creating a transport.
Connection * findConnection(const Tuple &tuple)
may return 0
void buildFdSet(FdSet &fdset)
void process(FdSet &fdset)
void setPollGrp(FdPollGrp *grp)
populate the fdset againt the read and write lists
static uint64_t MinimumGcAge
connection must have no inbound traffic for greater than this time (in ms) before it is garbage colle...
virtual void invokeAfterSocketCreationFunc() const
Connection implements, via sockets, ConnectionBase for managed connections.
virtual bool checkConnectionTimedout()
bool mFirstWriteAfterConnectedPending
void requestWrite(SendData *sendData)
queue data to write and add this to writable list
An alternative to std::string, encapsulates an arbitrary buffer of bytes.
virtual FdPollItemHandle addPollItem(Socket sock, FdPollEventMask newMask, FdPollItemIf *item)=0
virtual ImplType getImplType() const =0
virtual void delPollItem(FdPollItemHandle handle)=0
Object-oriented wrapper for your platform's file-descriptor set.
bool readyToRead(Socket fd)
A templated, threadsafe message-queue class.
virtual bool shareStackProcessAndSelect() const
Returns true if this Transport should be included in the FdSet processing loop, false if the Transpor...
static Socket socket(TransportType type, IpVersion ipVer)
SelectInterruptor mSelectInterruptor
FdPollItemHandle mPollItemHandle
ConsumerFifoBuffer< SendData > mTxFifoOutBuffer
virtual void invokeAfterSocketCreationFunc() const
virtual void setPollGrp(FdPollGrp *grp)
void buildFdSet(FdSet &fdset)
Used to add the 'artificial' fd to the fdset that will be responsible for interrupting a subsequent s...
TcpBaseTransport(Fifo< TransactionMessage > &fifo, int portNum, IpVersion version, const Data &interfaceName, AfterSocketCreationFuncPtr socketFunc, Compression &compression, unsigned transportFlags=0, const Data &netNs=Data::Empty)
virtual void processPollEvent(FdPollEventMask mask)
Called by PollGrp when activity is possible.
Connection * makeOutgoingConnection(const Tuple &dest, TransportFailure::FailureReason &failCode, int &subCode)
static const size_t MaxReadSize
virtual void setRcvBufLen(int buflen)
virtual void buildFdSet(FdSet &fdset)
Adds the Transport's socket FD to the appropriate read or write sets as applicable.
virtual void process()
Version of process to be invoked periodically when using callback-based IO (via FdPollGrp).
virtual ~TcpBaseTransport()
int processListen()
This doesn't exist anywhere that I can find? !kw! void sendFromRoundRobin(FdSet& fdset);.
virtual void setPollGrp(FdPollGrp *grp)
static const size_t MaxWriteSize
void processAllWriteRequests()
Forms a connection if one doesn't exist, moves requests to the appropriate connection's fifo.
virtual void init()
Performs constructor activities that depend on virtual functions specified by derived classes.
virtual Connection * createConnection(const Tuple &who, Socket fd, bool server=false)=0
Makes new Connection using provided socket.
virtual void invokeAfterSocketCreationFunc() const
General exception class for Transport.
void drainDscpRefresh()
Serves a pending refresh and a pending report.
IpVersion ipVersion() const
const Data & netNs() const
void fail(const Data &tid, TransportFailure::FailureReason reason=TransportFailure::Failure, int subCode=0)
Posts a TransportFailure to the TransactionMessage Fifo.
void applySocketOptions(Socket sock) const
The one place a socket of this transport is configured.
static void error(int e)
Generates a generic log for the platform specific socket error number.
ProducerFifoBuffer< TransactionMessage > mStateMachineFifo
void setTcpConnectState(const Data &tid, TcpConnectState::State state)
Posts a TcpConnectState to the TransactionMessage Fifo.
Represents a network address.
sockaddr & getMutableSockaddr()
Retrieve the binary representation of the socket address for this tuple.
bool onlyUseExistingConnection
FlowKey mFlowKey
This is a (largely) opaque key that subclasses of Transport will use to help record/find flows.
void copySockaddrAnyPort(sockaddr *sa)
Get a copy of the socket address including the interface and not the port number.
const sockaddr & getSockaddr() const
Retrieve a const binary representation of the socket address for this tuple.
This file is used to handle compatibility fixes/tweaks so reSIProcate can function on multiple platfo...
#define RESIP_MAX_SOCKADDR_SIZE
dcm! – add UnusedChecking(_enum) below;
void(* AfterSocketCreationFuncPtr)(Socket s, int transportType, const char *file, int line)
unsigned short FdPollEventMask
bool configureConnectedSocket(Socket fd)
int closeSocket(Socket fd)
std::string strError(int err)
IpVersion
An enumeration of IP versions.
bool makeSocketNonBlocking(Socket fd)