1#if defined(HAVE_CONFIG_H)
9#if defined(HAVE_SYS_SOCKIO_H)
10#include <sys/sockio.h>
13#if defined(HAVE_SOCK_CLOEXEC)
14#include <sys/socket.h>
27#define RESIPROCATE_SUBSYSTEM Subsystem::TRANSPORT
33 const Data& interfaceObj,
36 unsigned transportFlags,
38 Transport(rxFifo, portNum, version, interfaceObj,
Data::Empty,
39 socketFunc, compression, transportFlags, netNs),
41 mInterruptorHandle(0),
42 mTxFifoOutBuffer(mTxFifo),
66 WarningLog(<<
"TX Fifo non-empty in ~InternalTransport! Has " <<
mTxFifo.size() <<
" messages.");
80#if defined(HAVE_SOCK_CLOEXEC)
81 const int sockCloexec = SOCK_CLOEXEC;
83 const int sockCloexec = 0;
91 fd =
::socket(ipVer ==
V4 ? PF_INET : PF_INET6, SOCK_DGRAM | sockCloexec, IPPROTO_UDP);
93 fd =
::socket(PF_INET, SOCK_DGRAM | sockCloexec, IPPROTO_UDP);
99 fd =
::socket(ipVer ==
V4 ? PF_INET : PF_INET6, SOCK_STREAM | sockCloexec, 0);
101 fd =
::socket(PF_INET, SOCK_STREAM | sockCloexec, 0);
117 if (!SetHandleInformation((HANDLE)fd, HANDLE_FLAG_INHERIT, 0))
123#elif !defined(HAVE_SOCK_CLOEXEC)
124 int flags = fcntl(fd, F_GETFD);
131 if (fcntl(fd, F_SETFD,
flags | FD_CLOEXEC) == -1)
144 if ( ::setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &on,
sizeof(on)) )
149 throw Exception(
"Failed setsockopt", __FILE__,__LINE__);
155 DebugLog (<<
"Creating fd=" << fd << (ipVer ==
V4 ?
" V4/" :
" V6/") << (type ==
UDP ?
"UDP" :
"TCP"));
173 if ( e == EADDRINUSE )
194 ErrLog (<<
"getsockname failed, error=" << e);
202 ErrLog (<<
"Could not make socket non-blocking " <<
port());
#define WarningLog(args_)
#define resip_assert(x)
This file needs to work for both C and C++ code.
static const struct nv flags[]
An alternative to std::string, encapsulates an arbitrary buffer of bytes.
virtual FdPollItemHandle addPollItem(Socket sock, FdPollEventMask newMask, FdPollItemIf *item)=0
virtual void delPollItem(FdPollItemHandle handle)=0
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...
virtual void poke()
Called when a writer is done adding messages to the TxFifo; this is used to interrupt the select call...
static Socket socket(TransportType type, IpVersion ipVer)
virtual void setCongestionManager(CongestionManager *manager)
SelectInterruptor mSelectInterruptor
virtual unsigned int getFifoSize() const
virtual void send(std::unique_ptr< SendData > data)
virtual bool isFinished() const
FdPollItemHandle mPollItemHandle
ConsumerFifoBuffer< SendData > mTxFifoOutBuffer
FdPollItemHandle mInterruptorHandle
InternalTransport(Fifo< TransactionMessage > &rxFifo, int portNum, IpVersion version, const Data &interfaceObj, AfterSocketCreationFuncPtr socketFunc=0, Compression &compression=Compression::Disabled, unsigned transportFlags=0, const Data &netNs=Data::Empty)
virtual ~InternalTransport()
virtual void invokeAfterSocketCreationFunc() const
virtual bool hasDataToSend() const
only applies to transports that shareStackProcessAndSelect
virtual void setPollGrp(FdPollGrp *grp)
Socket getReadSocket() const
virtual void handleProcessNotification()
Called by the stack when messages are posted to it.
General exception class for Transport.
The base class for Transport classes.
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.
sockaddr & getMutableSockaddr()
Retrieve the binary representation of the socket address for this tuple.
static const Data & toData(TransportType)
Converts the TransportType to a string representation of the transport type, e.g.
const Data & getNetNs() const
Get the netns for this Tuple.
static Data inet_ntop(const Tuple &tuple)
Converts the binary socket address to presentation format, via the DnsUtil::inet_ntop() method.
dcm! – add UnusedChecking(_enum) below;
void(* AfterSocketCreationFuncPtr)(Socket s, int transportType, const char *file, int line)
int closeSocket(Socket fd)
TransportType
An enumeration of transport protocols.
std::string strError(int err)
IpVersion
An enumeration of IP versions.
bool makeSocketNonBlocking(Socket fd)