28#define RESIPROCATE_SUBSYSTEM AppSubsystem::MOHPARKSERVER
39 for(
int i=0; i<MaxConnections; i++)
43 delete mConnection[i] ; mConnection[i]=0;
56 for (
int i=0 ; i<MaxConnections; i++)
62 mFd = ::socket(ipVer ==
V4 ? PF_INET : PF_INET6, SOCK_STREAM, 0);
64 mFd = ::socket(PF_INET, SOCK_STREAM, 0);
70 ErrLog (<<
"Failed to create socket: " << strerror(e));
75 DebugLog (<<
"Creating fd=" << (
int)mFd
76 << (ipVer ==
V4 ?
" V4/" :
" V6/") );
80 if ( ::setsockopt ( mFd, SOL_SOCKET, SO_REUSEADDR, &on,
sizeof(on)) )
82 if ( ::setsockopt ( mFd, SOL_SOCKET, SO_REUSEADDR, (
const char*)&on,
sizeof(on)) )
86 ErrLog (<<
"Couldn't set sockoptions SO_REUSEPORT | SO_REUSEADDR: " << strerror(e));
96 if ( e == EADDRINUSE )
98 ErrLog (<< mTuple <<
" already in use ");
102 ErrLog (<<
"Could not bind to " << mTuple);
111 ErrLog (<<
"Could not make HTTP socket non-blocking " << port );
119 int e = listen(mFd,5 );
124 InfoLog (<<
"Failed listen " << strerror(e));
136 for(
int i=0; i<MaxConnections; i++)
138 if ( mConnection[i] )
153 socklen_t peerLen = tuple.
length();
154 Socket sock = accept( mFd, &peer, &peerLen);
164 ErrLog(<<
"Some error reading from socket: " << e);
173 int c = nextConnection;
174 nextConnection = ( nextConnection+1 ) % MaxConnections;
176 if ( mConnection[c] )
178 delete mConnection[c]; mConnection[c] = 0;
183 DebugLog (<<
"Received TCP connection as connection=" << c <<
" fd=" << (
int)sock);
186 for(
int i=0; i<MaxConnections; i++)
188 if ( mConnection[i] )
190 bool ok = mConnection[i]->
process(fdset);
193 delete mConnection[i]; mConnection[i]=0;
202 for (
int i=0 ; i<MaxConnections; i++)
204 if ( mConnection[i] )
206 if ( mConnection[i]->mPageNumber == pageNumber )
208 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)
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.
dcm! – add UnusedChecking(_enum) below;
IpVersion
An enumeration of IP versions.
bool makeSocketNonBlocking(Socket fd)