1. Cocoahttpserver
1) httpserver
[httpserver start: &error]
2) httpconnection
[Newconnection start]
3) Httpmessage HttpResponse
-(void) Socket: (gcdasyncsocket *) sock didreaddata: (nsdata*) data withtag: (long) tag
{
...
//Respond properly to HTTP ' GET ' and ' HEAD ' commands
HttpResponse = [self httpresponseformethod: Method uri: URI];
if (httpresponse = = nil)
{
[self handleresourcenotfound];
return;
}
[self sendresponseheadersandbody];
https://github.com/aldrinmartoq/brayatan/
Https://github.com/robbiehanson/CocoaHTTPServer
2.poco
voidTcpserverdispatcher::run () {autoptr<TCPServerDispatcher> Guard ( This,true);//ensure object stays alive intIdleTime = (int) _pparams->getthreadidletime (). TotalMilliseconds (); for (;;) {Autoptr<Notification> pNf =_queue.waitdequeuenotification (idleTime); if(pNf) {tcpconnectionnotification* pcnf = dynamic_cast<tcpconnectionnotification*> (pNf.Get()); if(pcnf) {std::auto_ptr<TCPServerConnection> pconnection (_pconnectionfactory->createconnection (pcnf->socket ())); Poco_check_ptr (pconnection.Get()); BeginConnection (); Pconnection-start (); EndConnection (); }} Fastmutex::scopedlockLock(_mutex); if(_stopped | | (_currentthreads >1&&_queue.empty ())) { --_currentthreads; Break; } }}
voidHttpserverconnection::run () {std::stringServer = _pparams->getsoftwareversion (); Httpserversession session (socket (), _pparams); while(!_stopped &&session.hasmorerequests ()) { Try{Poco::fastmutex::scopedlockLock(_mutex); if(!_stopped) {Httpserverresponseimpl response (session); Httpserverrequestimpl request (response, session, _pparams); Poco::timestamp now; Response.setdate (now); Response.setversion (Request.getversion ()); Response.setkeepalive (_pparams->getkeepalive () && request.getkeepalive () &&session.cankeepalive ()); if(!Server.empty ()) response.Set("Server", server); Try{std::auto_ptr<HTTPRequestHandler> Phandler (_pfactory->CreateRequestHandler (Request)); if(Phandler.Get()) { if(Request.expectcontinue ()) response.sendcontinue (); Phandler-HandleRequest (request, response); Session.setkeepalive (_pparams->getkeepalive () && response.getkeepalive () &&session.cankeepalive ()); } ElseSenderrorresponse (Session, httpresponse::http_not_implemented); } Catch(poco::exception&) { if(!response.sent ()) { Try{Senderrorresponse (session, Httpresponse::http_internal_server_err OR); } Catch (...) { } } Throw; } } } Catch(nomessageexception&) { Break; } Catch(messageexception&) {Senderrorresponse (session, Httpresponse::http_bad_request); } }}
classTimerequesthandler: PublicHttprequesthandler///Return a HTML document with the current date and time.{ Public: Timerequesthandler (ConstSTD::string&format): _format (format) {}voidHandleRequest (httpserverrequest& request, httpserverresponse&response) {Application& app =application::instance (); App.logger (). Information ("Request from"+request.clientaddress (). toString ()); Timestamp now; STD::stringDT (Datetimeformatter::format (now, _format)); Response.setchunkedtransferencoding (true); Response.setcontenttype ("text/html"); Std::ostream& ostr =Response.send (); Ostr<<""; Ostr<<"<meta http-equiv=\ "refresh\" content=\ "1\" >"; Ostr<<"<body><p style=\ "Text-align:center font-size:48px;\" >"; Ostr<<DT; Ostr<<"</p></body>"; }Private: std::string_format;};
7th Month 26th Day IOS httpserver