27#define RESIPROCATE_SUBSYSTEM Subsystem::REPRO
38 for(
int i=0; i<MaxConnections; i++)
42 delete mConnection[i] ; mConnection[i]=0;
51 mTuple(ipAddr,port,ipVer,
TCP,
Data::Empty)
58 for (
int i=0 ; i<MaxConnections; i++)
64 mFd = ::socket(ipVer ==
V4 ? PF_INET : PF_INET6, SOCK_STREAM, 0);
66 mFd = ::socket(PF_INET, SOCK_STREAM, 0);
77 DebugLog (<<
"Creating fd=" << (
int)mFd
78 << (ipVer ==
V4 ?
" V4/" :
" V6/") );
82 if ( ::setsockopt ( mFd, SOL_SOCKET, SO_REUSEADDR, &on,
sizeof(on)) )
84 if ( ::setsockopt ( mFd, SOL_SOCKET, SO_REUSEADDR, (
const char*)&on,
sizeof(on)) )
88 ErrLog (<<
"Couldn't set sockoptions SO_REUSEPORT | SO_REUSEADDR: " <<
strError(e));
97 if ( ::setsockopt(mFd, IPPROTO_IPV6, IPV6_V6ONLY, &on,
sizeof(on)) )
100 ErrLog(<<
"HttpBase::HttpBase: Couldn't set sockoptions IPV6_V6ONLY: " <<
strError(e));
113 if ( e == EADDRINUSE )
115 ErrLog (<< mTuple <<
" already in use ");
119 ErrLog (<<
"Could not bind to " << mTuple);
128 ErrLog (<<
"Could not make HTTP socket non-blocking " << port );
136 int e = listen(mFd,5 );
153 for(
int i=0; i<MaxConnections; i++)
155 if ( mConnection[i] )
170 socklen_t peerLen = tuple.
length();
171 Socket sock = accept( mFd, &peer, &peerLen);
178#if EAGAIN != EWOULDBLOCK
184 ErrLog(<<
"Some error reading from socket: " << e);
193 int c = nextConnection;
194 nextConnection = ( nextConnection+1 ) % MaxConnections;
196 if ( mConnection[c] )
198 delete mConnection[c]; mConnection[c] = 0;
203 DebugLog (<<
"Received TCP connection as connection=" << c <<
" fd=" << (
int)sock);
206 for(
int i=0; i<MaxConnections; i++)
208 if ( mConnection[i] )
210 bool ok = mConnection[i]->
process(fdset);
213 delete mConnection[i]; mConnection[i]=0;
227 for (
int i=0 ; i<MaxConnections; i++)
229 if ( mConnection[i] )
231 if ( mConnection[i]->mPageNumber == pageNumber )
233 mConnection[i]->
setPage( page,response,type );
Handles cross-platform sockets compatibility.
void setPage(const resip::Data &page, int pageNumber, int response=200, const resip::Mime &pType=resip::Mime("text","html"))
HttpBase(int port, resip::IpVersion version, const resip::Data &realm, const resip::Data &ipAddr=resip::Data::Empty)
void buildFdSet(resip::FdSet &fdset)
friend class HttpConnection
void process(resip::FdSet &fdset)
bool process(resip::FdSet &fdset)
void buildFdSet(resip::FdSet &fdset)
void setPage(const resip::Data &page, int response, const resip::Mime &pType)
An alternative to std::string, encapsulates an arbitrary buffer of bytes.
Object-oriented wrapper for your platform's file-descriptor set.
bool readyToRead(Socket fd)
Represents the "media-type" element in the RFC 3261 grammar.
Represents a network address.
sockaddr & getMutableSockaddr()
Retrieve the binary representation of the socket address for this tuple.
static Data inet_ntop(const Tuple &tuple)
Converts the binary socket address to presentation format, via the DnsUtil::inet_ntop() method.
This Class is used to implement a primitive form of RPC using loose XML formatting.
dcm! – add UnusedChecking(_enum) below;
std::string strError(int err)
IpVersion
An enumeration of IP versions.
bool makeSocketNonBlocking(Socket fd)