void FileUpload::Execute() { if (HasRequest() && mState != eClient_STATE_CONNECTED) // 有上传请求 && 尚未连接 { TryConnectServer(); } if (mState == eClient_STATE_CONNECTED) // 已连接上 { //if (CanSendData()) { UploadRequest* Req = PopRequest(); if (Req) { if (HandleRequest(Req)) { // Req已放入WaitingList, 暂不回收 } else { AddResponse(*Req, false, ""); delete Req; } } } if (CanRecvData() && mRecvSize < MAX_RECV_BUFF_SIZE) { int Ret = recv(mSocket, &mRecvBuff[mRecvSize], MAX_RECV_BUFF_SIZE - mRecvSize, 0); if (Ret == SOCKET_ERROR || Ret <= 0) { CloseSocket(eClient_STATE_ABORT, true); // TODO: 当服务器send主动关闭时 (应该至少还能recv一次, 没问题) } else { mRecvSize += Ret; } } } ServerResponse SrvRep; if (TryDecodeRecvBuff(SrvRep)) { auto Itr = mWaitingList.find(SrvRep.mSrvFileName); if (Itr != mWaitingList.end()) { auto Req = Itr->second; if (Req) { AddResponse(*Req, SrvRep.mFlag == 0x00A2, SrvRep.mSrvFileName); delete Req; } mWaitingList.erase(Itr); } } WaitFor(1); }
// }}} // {{{ void Status::testStopping() void Status::testStopping() { wxString reason; AddResponse(wxT("xml/status/stopping.xml")); conn->ProcessNextResponse(); DBGp::Connection::EngineStatus status(conn->Status(&reason)); CPPUNIT_ASSERT(status == DBGp::Connection::STOPPING); CPPUNIT_ASSERT(reason == wxT("ok")); }
// {{{ void Status::testBreak() void Status::testBreak() { wxString reason; AddResponse(wxT("xml/status/break.xml")); conn->ProcessNextResponse(); DBGp::Connection::EngineStatus status(conn->Status(&reason)); CPPUNIT_ASSERT(status == DBGp::Connection::BREAK); CPPUNIT_ASSERT(reason == wxT("ok")); }
_SUB void LinkInSensitivity(CHANNEL_TIMES *inchannel,SENSITIVITY *insens, int stage) { RESPONSE *rp; rp = AddResponse(inchannel,RESP_SENSITIVITY, (void *) insens, stage); }
_SUB void LinkInDecimation(CHANNEL_TIMES *inchannel,DECIMATION *indeci, int stage) { RESPONSE *rp; rp = AddResponse(inchannel,RESP_DECIMATION, (void *) indeci, stage); }
_SUB void LinkInCoefficients(CHANNEL_TIMES *inchannel,COEFFICIENTS *incoef, int stage) { RESPONSE *rp; rp = AddResponse(inchannel,RESP_COEFFICIENTS,(void *) incoef,stage); }
_SUB void LinkInZerosPoles(CHANNEL_TIMES *inchannel,ZEROS_POLES *inzero, int stage) { RESPONSE *rp; rp = AddResponse(inchannel,RESP_ZEROS_POLES, (void *) inzero, stage); }
// }}} // {{{ void Status::testStatusChange() void Status::testStatusChange() { AddResponse(wxT("xml/status/run.xml")); conn->ProcessNextResponse(); conn->Run(); CPPUNIT_ASSERT(lastEvent != NULL); DBGp::StatusChangeEvent *e = dynamic_cast<DBGp::StatusChangeEvent *>(lastEvent); CPPUNIT_ASSERT(e != NULL); CPPUNIT_ASSERT(e->GetStatus() == DBGp::Connection::BREAK); }
BOOL TmHandleReponseMessage(MESSAGE *message) { struct StatusLine *status = NULL; int statusCode = 0; struct Transaction *t = NULL; status = MessageGetStatusLine(message); statusCode = StatusLineGetStatusCode(status); t = MatchResponse(message); if (t) { AddResponse(t, message); RunFsm(t, MapStatusCodeToEvent(statusCode)); return TRUE; } return FALSE; }
void FileUpload::ClearWaitingList(bool Notify) { while (mWaitingList.size() > 0) { auto Itr = mWaitingList.begin(); auto Req = Itr->second; if (Req) { if (Notify) { AddResponse(*Req, false, ""); } delete Req; } mWaitingList.erase(Itr); } }
void StatsInterface::HandleStmgrsRegistrationSummaryRequest(IncomingHTTPRequest* _request) { LOG(INFO) << "Request for stream managers registration summary " << _request->GetQuery(); unsigned char* request_data = _request->ExtractFromPostData(0, _request->GetPayloadSize()); heron::proto::tmaster::StmgrsRegistrationSummaryRequest stmgrs_reg_request; if (!stmgrs_reg_request.ParseFromArray(request_data, _request->GetPayloadSize())) { LOG(ERROR) << "Unable to deserialize post data specified in" << "StmgrsRegistrationSummaryRequest" << std::endl; http_server_->SendErrorReply(_request, 400); delete _request; return; } auto stmgrs_reg_summary_response = tmaster_->GetStmgrsRegSummary(); sp_string response_string; CHECK(stmgrs_reg_summary_response->SerializeToString(&response_string)); auto http_response = new OutgoingHTTPResponse(_request); http_response->AddHeader("Content-Type", "application/octet-stream"); http_response->AddHeader("Content-Length", std::to_string(response_string.size())); http_response->AddResponse(response_string); http_server_->SendReply(_request, 200, http_response); delete _request; LOG(INFO) << "Returned stream managers registration summary response"; }
bool CStimResponseCollection::ParseSpawnArg( const idDict &args, idEntity *owner, const char sr_class, int index ) { bool rc = false; idStr str; CStimPtr stim; CResponsePtr resp; CStimResponsePtr sr; StimState state( SS_DISABLED ); StimType typeOfStim; // Check if the entity contains either a stim or a response. if( sr_class != 'S' && sr_class != 'R' ) { DM_LOG( LC_STIM_RESPONSE, LT_ERROR )LOGSTRING( "Invalid sr_class value [%s]\r", str.c_str() ); goto Quit; } // Get the id of the stim/response type so we know what sub-class to create args.GetString( va( "sr_type_%u", index ), "-1", str ); // This is invalid as an entity definition if( str == "-1" ) { sr.reset(); goto Quit; } // If the first character is alphanumeric, we check if it // is a known id and convert it. /* StimType */ typeOfStim = ST_DEFAULT; if( ( str[0] >= 'a' && str[0] <= 'z' ) || ( str[0] >= 'A' && str[0] <= 'Z' ) ) { // Try to recognise the string as known Stim type typeOfStim = CStimResponse::GetStimType( str ); // If the string hasn't been found, we have id == ST_DEFAULT. if( typeOfStim == ST_DEFAULT ) { DM_LOG( LC_STIM_RESPONSE, LT_ERROR )LOGSTRING( "Invalid sr_type id [%s]\r", str.c_str() ); sr.reset(); goto Quit; } } else if( str[0] >= '0' && str[0] <= '9' ) { // Is it numeric? typeOfStim = ( StimType ) atol( str.c_str() ); } else { // neither a character nor a number, thus it is invalid. DM_LOG( LC_STIM_RESPONSE, LT_ERROR )LOGSTRING( "Invalid sr_type id [%s]\r", str.c_str() ); sr.reset(); goto Quit; } if( sr_class == 'S' ) { stim = CreateStim( owner, typeOfStim ); if( stim == NULL ) { // grayman #2862 goto Quit; // nasty goto!! } sr = stim; } else if( sr_class == 'R' ) { resp = CreateResponse( owner, typeOfStim ); sr = resp; } // Set stim response type sr->m_StimTypeId = typeOfStim; // Set stim response name string sr->m_StimTypeName = str; // Read stim response state from the def file state = static_cast<StimState>( args.GetInt( va( "sr_state_%u", index ), "1" ) ); sr->SetEnabled( state == SS_ENABLED ); sr->m_Chance = args.GetFloat( va( "sr_chance_%u", index ), "1.0" ); // A stim also may have a radius if( sr_class == 'S' ) { stim->m_Radius = args.GetFloat( va( "sr_radius_%u", index ), "0" ); stim->m_RadiusFinal = args.GetFloat( va( "sr_radius_final_%u", index ), "-1" ); stim->m_FallOffExponent = args.GetInt( va( "sr_falloffexponent_%u", index ), "0" ); stim->m_bUseEntBounds = args.GetBool( va( "sr_use_bounds_%u", index ), "0" ); stim->m_bCollisionBased = args.GetBool( va( "sr_collision_%u", index ), "0" ); stim->m_Velocity = args.GetVector( va( "sr_velocity_%u", index ), "0 0 0" ); stim->m_Bounds[0] = args.GetVector( va( "sr_bounds_mins_%u", index ), "0 0 0" ); stim->m_Bounds[1] = args.GetVector( va( "sr_bounds_maxs_%u", index ), "0 0 0" ); // set up time interleaving so the stim isn't fired every frame stim->m_TimeInterleave = args.GetInt( va( "sr_time_interval_%u", index ), "0" ); // greebo: Add fuzzyness to the timer (ranging from 0.9 - 1.3); stim->m_TimeInterleave = static_cast<int>( stim->m_TimeInterleave * ( 0.9f + gameLocal.random.RandomFloat() * 0.4f ) ); // userfriendly stim duration time stim->m_Duration = args.GetInt( va( "sr_duration_%u", index ), "0" ); stim->m_Magnitude = args.GetFloat( va( "sr_magnitude_%u", index ), "1.0" ); stim->m_MaxFireCount = args.GetInt( va( "sr_max_fire_count_%u", index ), "-1" ); // Check if we have a timer on this stim. CreateTimer( args, stim, index ); } else { // this is only for responses sr->m_ChanceTimer = args.GetInt( va( "sr_chance_timeout_%u", index ), "-1" ); resp->m_NumRandomEffects = args.GetInt( va( "sr_random_effects_%u", index ), "0" ); // Get the name of the script function for processing the response args.GetString( "sr_script_" + str, "", str ); resp->m_ScriptFunction = str; // Try to identify the ResponseEffect spawnargs int effectIdx = 1; while( effectIdx > 0 ) { // Try to find a string like "sr_effect_2_1" args.GetString( va( "sr_effect_%u_%u", index, effectIdx ), "", str ); if( str.IsEmpty() ) { // Set the index to negative values to end the loop effectIdx = -1; } else { // Assemble the postfix of this effect for later key/value lookup // This is passed to the effect script eventually DM_LOG( LC_STIM_RESPONSE, LT_DEBUG )LOGSTRING( "Adding response effect\r" ); resp->AddResponseEffect( str, va( "%u_%u", index, effectIdx ), args ); effectIdx++; } } } rc = true; Quit: if( sr != NULL ) { if( stim != NULL ) { DM_LOG( LC_STIM_RESPONSE, LT_DEBUG )LOGSTRING( "Stim %s added to collection for %s\r", stim->m_StimTypeName.c_str(), owner->name.c_str() ); AddStim( stim ); stim->m_State = state; } if( resp != NULL ) { DM_LOG( LC_STIM_RESPONSE, LT_DEBUG )LOGSTRING( "Response %s added to collection for %s\r", resp->m_StimTypeName.c_str(), owner->name.c_str() ); AddResponse( resp ); } } return rc; }