Ejemplo n.º 1
0
void RcfProtoChannel::onCompletionCpp()
{
    Message * pResponse = mpResponse;
    Closure * pClosure = mpClosure;

    mpRequest = NULL;
    mpResponse = NULL;
    mpClosure = NULL;

    bool sync = !mAsyncRpcMode;
    if (sync)
    {
        // Synchronous completion.

        RCF_ASSERT(!pClosure);
        if (mError.bad())
        {
            throw mError;
        }

        if (pResponse)
        {
            pResponse->ParseFromArray(
                mResponseBuffer.getPtr(), 
                (int) mResponseBuffer.getLength());
        }
    }
    else
    {
        // Asynchronous completion.

        RCF_ASSERT(pClosure);
        std::auto_ptr<RCF::Exception> ePtr = mFuture.getAsyncException();
        if (ePtr.get())
        {
            mError = *ePtr;
        }
        else
        {
            mResponseBuffer = *mFuture;
        }

        if (mError.good() && pResponse)
        {
            pResponse->ParseFromArray(
                mResponseBuffer.getPtr(), 
                (int) mResponseBuffer.getLength());
        }
        
        pClosure->Run();
    }
}
Ejemplo n.º 2
0
void HttpRpcRequest::onHttpRequestCompleted(FHttpRequestPtr request, FHttpResponsePtr response, bool bWasSuccessful) {
	if (!bWasSuccessful) {
		UE_LOG(HttpRpcRequestLog, Error, TEXT("HTTP request failed"));
		callState_.GetController()->SetFailed("HTTP request failed");
	} else {
		const int responseCode = response->GetResponseCode();
		if (responseCode != 200) {
			if ((responseCode >= 300) && (responseCode < 400)) {
				// TODO(san): Handle redirects.
				callState_.GetController()->SetFailed("Unsupported redirect");
			} else {
				UE_LOG(HttpRpcRequestLog, Error, TEXT("HTTP response code %d (%s)"), response->GetResponseCode(), *response->GetContentAsString());
				callState_.GetController()->SetFailed("Bad HTTP response code");
			}
		} else {
			// Successful HTTP response.
			int requestId = ParseRequestIdFromResponse(response);
			if (requestId == -1) {
				UE_LOG(HttpRpcRequestLog, Error, TEXT("HTTP response missing request id"));
				callState_.GetController()->SetFailed("Response missing request id");
				// TODO(san): Think about whether we should be strict about this given we have the request handy.
			} else if (requestId != FCString::Atoi(*request->GetHeader("X-Request-ID"))) {
				// If this happens legitimately then we are most likely inheriting a 'threading issue' from the
				// HTTP module - in which case we'll probably need to track outstanding requests ourselves.
				UE_LOG(HttpRpcRequestLog, Error, TEXT("Mismatched Request/Response!"));
				callState_.GetController()->SetFailed("Mismatched Request/Response ID");
			} else {
				// Request ID is valid. Extract the protobuf from the HTTP content buffer.
				if (!ParseMessageFromResponse(response)) {
					UE_LOG(HttpRpcRequestLog, Warning, TEXT("Failed to parse response protobuf"));
					callState_.GetController()->SetFailed("Failed to parse response protobuf");
				}
			}
		}
	}

	Closure* cachedClosure = callState_.GetDone();
	delete this;
	cachedClosure->Run();
}
Ejemplo n.º 3
0
void TinyThread::Routine()
{
    mFunc->Run();
    delete this;
}