void EHSConnection::SendHttpResponse ( HttpResponse * ipoHttpResponse ) { // only send it if the client isn't disconnected if ( Disconnected ( ) ) { return; } std::string sOutput; char psSmallBuffer [ 20 ]; sOutput = "HTTP/1.1 "; // add in the response code sprintf ( psSmallBuffer, "%d", ipoHttpResponse->m_nResponseCode ); sOutput += psSmallBuffer; sOutput += " "; sOutput += GetResponsePhrase ( ipoHttpResponse->m_nResponseCode ); sOutput += "\r\n"; // now go through all the entries in the responseheaders string map for ( StringMap::iterator oCurrentHeader = ipoHttpResponse->oResponseHeaders.begin ( ); oCurrentHeader != ipoHttpResponse->oResponseHeaders.end ( ); oCurrentHeader++ ) { sOutput += (*oCurrentHeader).first; sOutput += ": "; sOutput += (*oCurrentHeader).second; sOutput += "\r\n"; } // now push out all the cookies for ( StringList::iterator i = ipoHttpResponse->oCookieList.begin ( ); i != ipoHttpResponse->oCookieList.end ( ); i++ ) { sOutput += "Set-Cookie: "; sOutput += *i; sOutput += "\r\n"; } // extra line break signalling end of headers sOutput += "\r\n"; int ret = TrySend ( sOutput.c_str (), sOutput.length() ); if ( ret == -1 ) return; // now send the body TrySend ( ipoHttpResponse->GetBody ( ), atoi ( ipoHttpResponse->oResponseHeaders [ "content-length" ].c_str ( ) ) ); }
//--------------------------------------------------------------------------------------- static int MasterRelease( tGroupRegistration* pGroup, tBool sendNow ) { int result = AppCommandLocal( pGroup, ArbitrationCmd_MasterRelease, 0 ); assert( result >= 0 ); pGroup->state = State_Unknown; SetupSend( pGroup, ArbitrationPGNCmd_Release ); if (sendNow) { TrySend( pGroup ); } return result; }
//--------------------------------------------------------------------------------------- static void UpdateGroupTimers( tGroupRegistration* pGroup ) { if (pGroup->timer != 0) pGroup->timer--; if (pGroup->timer == 0) { int result; if (pGroup->sendCount == 0) { // no pending sends if ((pGroup->statusFlags & ArbitrationFlags_NoComms) && IsNoComms() == tFalse) { // bus has come back, force re-arbitration pGroup->statusFlags &= ~ArbitrationFlags_NoComms; if (pGroup->state == State_Master) { result = AppCommandLocal( pGroup, ArbitrationCmd_MasterRelease, 0 ); assert( result >= 0 ); } pGroup->state = State_Unknown; pGroup->timer = TIMEOUT_NOMASTER_FIRST; SetupSend( pGroup, ArbitrationPGNCmd_NewMember ); } else { switch (pGroup->state) { case State_Unknown: case State_IsMaster: // haven't seen any master broadcast, see if we should take over result = AppCommandLocal( pGroup, ArbitrationCmd_MasterMissing, 0 ); if (result == ARBITRATION_OK_ACQUIRE && IsAllowedToAcquire( pGroup )) { SetupSend( pGroup, ArbitrationPGNCmd_Acquire ); } else { pGroup->state = State_NoMaster; pGroup->timer = TIMEOUT_NOMASTER_FIRST; } break; case State_NoMaster: // haven't seen any master broadcast, see if we want to take over now result = AppCommandLocal( pGroup, ArbitrationCmd_MasterStillMissing, 0 ); if (result == ARBITRATION_OK_ACQUIRE && IsAllowedToAcquire( pGroup )) { SetupSend( pGroup, ArbitrationPGNCmd_Acquire ); } else { pGroup->timer = TIMEOUT_NOMASTER_STILL; } break; case State_Acquire: // no successful challenge to becoming the master, so lets do it assert( (pGroup->options & ArbitrationOpt_Watcher) == 0 ); result = AppCommandLocal( pGroup, ArbitrationCmd_MasterPending, 0 ); if (result >= 0) { // still want to become the master SetupSend( pGroup, ArbitrationPGNCmd_Master ); } else { // apparently we don't want to become the master anymore pGroup->state = State_Unknown; pGroup->timer = TIMEOUT_MASTER_ABORTED; } break; case State_Master: // time to brag again assert( (pGroup->statusFlags & (ArbitrationFlags_Watcher|ArbitrationFlags_NotSuitable)) == 0 ); result = AppCommandLocal( pGroup, ArbitrationCmd_MasterCheck, 0 ); if (result >= 0) { // still want to be master SetupSend( pGroup, ArbitrationPGNCmd_Master ); } else { // don't want to be master anymore MasterRelease( pGroup, tFalse ); } break; default: assert( 0 ); } } } } if (pGroup->sendCount > 0) { TrySend( pGroup ); } }
//--------------------------------------------------------------------------------------- static void DoSend( tGroupRegistration* pGroup, eArbitrationPGNCommand cmd ) { SetupSend( pGroup, cmd ); TrySend( pGroup ); }