TInt RWin32Socket::GetPeerName(TInetAddr& aAddress) const { WSP_LOG(WspLog::Printf(_L("RWin32Socket::GetPeerName: this: 0x%x"), this)); TRequestStatus status; iWin32Message.Set(CWin32Socket::EGetPeerName, aAddress, status); TInt err = MakeRequest(iWin32Message); if (err) { return err; } else { User::WaitForRequest(status); return status.Int(); } }
TInt RWin32Socket::Listen(TUint aQueueSize) { WSP_LOG(WspLog::Printf(_L("RWin32Socket::Listen: this: 0x%x"), this)); TPckgC<TUint> queueSizePckg(aQueueSize); TRequestStatus status; iWin32Message.Set(CWin32Socket::EListen, queueSizePckg, status); TInt err = MakeRequest(iWin32Message); if (err) { return err; } else { User::WaitForRequest(status); return status.Int(); } }
TInt RWin32Socket::SetOption(TInt aLevel, TInt aName, const char* aValue, TInt aLength) { WSP_LOG(WspLog::Printf(_L("RWin32Socket::SetOption: this: 0x%x"), this)); TWin32SocketOptionsC options = {aLevel, aName, aValue, aLength}; TPckgC<TWin32SocketOptionsC> optionsPckg(options); TRequestStatus status; iWin32Message.Set(CWin32Socket::ESetOption, optionsPckg, status); TInt err = MakeRequest(iWin32Message); if (err) { return err; } else { User::WaitForRequest(status); return status.Int(); } }
static HRESULT GetResourceMetadata( __in BURN_USER_EXPERIENCE* pUX, __in_z LPCWSTR wzPackageOrContainerId, __in_z LPCWSTR wzPayloadId, __in HINTERNET hSession, __inout_z LPWSTR* psczUrl, __in_z_opt LPCWSTR wzUser, __in_z_opt LPCWSTR wzPassword, __out DWORD64* pdw64ResourceSize, __out FILETIME* pftResourceCreated ) { HRESULT hr = S_OK; BOOL fRangeRequestsAccepted = TRUE; HINTERNET hConnect = NULL; HINTERNET hUrl = NULL; LONGLONG llLength = 0; hr = MakeRequest(pUX, wzPackageOrContainerId, wzPayloadId, hSession, psczUrl, L"HEAD", NULL, wzUser, wzPassword, &hConnect, &hUrl, &fRangeRequestsAccepted); ExitOnFailure1(hr, "Failed to connect to URL: %ls", *psczUrl); hr = InternetGetSizeByHandle(hUrl, &llLength); if (FAILED(hr)) { llLength = 0; hr = S_OK; } *pdw64ResourceSize = llLength; // Get the last modified time from the server, we'll use that as our downloaded time here. If // the server time isn't available then use the local system time. hr = InternetGetCreateTimeByHandle(hUrl, pftResourceCreated); if (FAILED(hr)) { ::GetSystemTimeAsFileTime(pftResourceCreated); hr = S_OK; } LExit: ReleaseInternet(hUrl); ReleaseInternet(hConnect); return hr; }
QByteArray NetworkRequest::runSync( const QUrl& url ) { DebugPrintFunc( "NetworkRequest::runSync", url.toString() ); data.clear(); reply = MakeRequest( url ); QEventLoop loop; connect( reply.data(), &QNetworkReply::downloadProgress, this, [this] (quint64 received, quint64 total) { emit Progress( received, total ); } ); connect( reply.data(), &QNetworkReply::readyRead, this, &NetworkRequest::ReadyRead ); connect( reply.data(), &QNetworkReply::finished, this, &NetworkRequest::CheckForRedirect ); connect( reply.data(), &QNetworkReply::finished, &loop, &QEventLoop::quit ); loop.exec(); DebugPrint( QString( "Loaded: %1 bytes" ).arg( data.size() ) ); DebugPrintFuncDone( "NetworkRequest::runSync" ); reply->deleteLater(); return( data ); }
void CloudyWebAPIImpl::GetSaveFileUrl(int32 GameId, FString Username, int32 PlayerControllerId) { CURLcode ret; CURL *hnd; struct curl_slist *slist1; slist1 = NULL; std::string readBuffer; // Make authorization token header FString AuthHeader = "Authorization: Token " + Token; std::string AuthHeaderCString(TCHAR_TO_UTF8(*AuthHeader)); // Make URL for GET request FString SaveFileUrl = BaseUrl + SaveDataUrl + "?user="******"&game=" + FString::FromInt(GameId); std::string SaveFileUrlCString(TCHAR_TO_UTF8(*SaveFileUrl)); MakeRequest(SaveFileUrl, "GET"); slist1 = curl_slist_append(slist1, AuthHeaderCString.c_str()); hnd = curl_easy_init(); curl_easy_setopt(hnd, CURLOPT_URL, SaveFileUrlCString.c_str()); curl_easy_setopt(hnd, CURLOPT_HTTPHEADER, slist1); curl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, "GET"); /* Set up string to write response into */ curl_easy_setopt(hnd, CURLOPT_WRITEFUNCTION, WriteCallback); curl_easy_setopt(hnd, CURLOPT_WRITEDATA, &readBuffer); // Make the GET request ret = curl_easy_perform(hnd); // Cleanup curl_easy_cleanup(hnd); hnd = NULL; curl_slist_free_all(slist1); slist1 = NULL; UE_LOG(CloudyWebAPILog, Warning, TEXT("Response data: %s"), UTF8_TO_TCHAR(readBuffer.c_str())); ReadAndStoreSaveFileURL(UTF8_TO_TCHAR(readBuffer.c_str()), PlayerControllerId); }
void CDiskSpaceNotifier::RunL() { TInt err = iStatus.Int(); assert((err != KErrArgument) && "threshold value outside its limits"); /* xxx When could we get this? Not documented. if (err == KErrCorrupt) { return; } */ // Make new request before notification, do nothing after the callback. MakeRequest(); /* if (err != KErrNone) { logg("Unexpected, got error %d in DiskSpaceNotifier!", err); } */ // Leave it to the caller to decide what to do about any possible error. iNotifier->DiskSpaceNotify(iDrive, err); }
void CDiskSpaceNotifier::ConstructL() { MakeRequest(); // activate at initialization already }
//-------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------- HttpRequest* HttpRequestSystem::MakeGetRequest(const std::string& in_url, const HttpRequest::Delegate& in_delegate, u32 in_timeoutSecs) { return MakeRequest(HttpRequest::Type::k_get, in_url, "", ChilliSource::ParamDictionary(), in_delegate, in_timeoutSecs); }
//-------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------- HttpRequest* HttpRequestSystem::MakePostRequest(const std::string& in_url, const std::string& in_body, const ChilliSource::ParamDictionary& in_headers, const HttpRequest::Delegate& in_delegate, u32 in_timeoutSecs) { return MakeRequest(HttpRequest::Type::k_post, in_url, in_body, in_headers, in_delegate, in_timeoutSecs); }
TInt RWin32Socket::Connect(const TInetAddr& aAddress, TRequestStatus& aStatus) { WSP_LOG(WspLog::Printf(_L("RWin32Socket::Connect: this: 0x%x"), this)); iWin32Message.Set(CWin32Socket::EConnect, aAddress, aStatus); return MakeRequest(iWin32Message); }
static HRESULT DownloadResource( __in BURN_USER_EXPERIENCE* pUX, __in_z LPCWSTR wzPackageOrContainerId, __in_z LPCWSTR wzPayloadId, __in HINTERNET hSession, __inout_z LPWSTR* psczUrl, __in_z_opt LPCWSTR wzUser, __in_z_opt LPCWSTR wzPassword, __in_z LPCWSTR wzDestinationPath, __in DWORD64 dw64AuthoredResourceLength, __in DWORD64 dw64ResourceLength, __in DWORD64 dw64ResumeOffset, __in HANDLE hResumeFile, __in_opt BURN_CACHE_CALLBACK* pCallback ) { HRESULT hr = S_OK; HANDLE hPayloadFile = INVALID_HANDLE_VALUE; DWORD cbMaxData = 64 * 1024; // 64 KB BYTE* pbData = NULL; BOOL fRangeRequestsAccepted = TRUE; LPWSTR sczRangeRequestHeader = NULL; HINTERNET hConnect = NULL; HINTERNET hUrl = NULL; LONGLONG llLength = 0; hPayloadFile = ::CreateFileW(wzDestinationPath, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_DELETE, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); if (INVALID_HANDLE_VALUE == hPayloadFile) { ExitWithLastError1(hr, "Failed to create download destination file: %ls", wzDestinationPath); } // Allocate a memory block on a page boundary in case we want to do optimal writing. pbData = static_cast<BYTE*>(::VirtualAlloc(NULL, cbMaxData, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE)); ExitOnNullWithLastError(pbData, hr, "Failed to allocate buffer to download files into."); // Let's try downloading the file assuming that range requests are accepted. If range requests // are not supported we'll have to start over and accept the fact that we only get one shot // downloading the file however big it is. Hopefully, not more than 2 GB since wininet doesn't // like files that big. while (fRangeRequestsAccepted && (0 == dw64ResourceLength || dw64ResumeOffset < dw64ResourceLength)) { hr = AllocateRangeRequestHeader(dw64ResumeOffset, 0 == dw64ResourceLength ? dw64AuthoredResourceLength : dw64ResourceLength, &sczRangeRequestHeader); ExitOnFailure(hr, "Failed to allocate range request header."); ReleaseNullInternet(hConnect); ReleaseNullInternet(hUrl); hr = MakeRequest(pUX, wzPackageOrContainerId, wzPayloadId, hSession, psczUrl, L"GET", sczRangeRequestHeader, wzUser, wzPassword, &hConnect, &hUrl, &fRangeRequestsAccepted); ExitOnFailure1(hr, "Failed to request URL for download: %ls", *psczUrl); // If we didn't get the size of the resource from the initial "HEAD" request // then let's try to get the size from this "GET" request. if (0 == dw64ResourceLength) { hr = InternetGetSizeByHandle(hUrl, &llLength); if (SUCCEEDED(hr)) { dw64ResourceLength = llLength; } else // server didn't tell us the resource length. { // Fallback to the authored size of the resource. However, since we // don't really know the size on the server, don't try to use // range requests either. dw64ResourceLength = dw64AuthoredResourceLength; fRangeRequestsAccepted = FALSE; } } // If we just tried to do a range request and found out that it isn't supported, start over. if (!fRangeRequestsAccepted) { // TODO: log a message that the server did not accept range requests. dw64ResumeOffset = 0; } hr = WriteToFile(hUrl, hPayloadFile, &dw64ResumeOffset, hResumeFile, dw64ResourceLength, pbData, cbMaxData, pCallback); ExitOnFailure1(hr, "Failed while reading from internet and writing to: %ls", wzDestinationPath); } LExit: ReleaseInternet(hUrl); ReleaseInternet(hConnect); ReleaseStr(sczRangeRequestHeader); if (pbData) { ::VirtualFree(pbData, 0, MEM_RELEASE); } ReleaseFileHandle(hPayloadFile); return hr; }
//-------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------- HttpRequest* HttpRequestSystem::MakePostRequest(const std::string& in_url, const std::string& in_body, const HttpRequest::Delegate& in_delegate, u32 in_timeoutSecs) { return MakeRequest(HttpRequest::Type::k_post, in_url, in_body, CSCore::ParamDictionary(), in_delegate, in_timeoutSecs); }
//-------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------- HttpRequest* HttpRequestSystem::MakeGetRequest(const std::string& in_url, const CSCore::ParamDictionary& in_headers, const HttpRequest::Delegate& in_delegate, u32 in_timeoutSecs) { return MakeRequest(HttpRequest::Type::k_get, in_url, "", in_headers, in_delegate, in_timeoutSecs); }
TInt RWin32Socket::Send(const TDesC8& aSendBuffer, TRequestStatus& aStatus) { WSP_LOG(WspLog::Printf(_L("RWin32Socket::Send: this: 0x%x, bytes to send: %d"), this, aSendBuffer.Length())); iWin32Message.Set(CWin32Socket::ESend, aSendBuffer, aStatus); return MakeRequest(iWin32Message); }
void RWin32Socket::CancelReceive() { TWin32Message cancelWin32Message; cancelWin32Message.Set(CWin32Socket::ECancelReceive); MakeRequest(cancelWin32Message); // Throw away return code - can't do anything useful with it. }
TInt RWin32Socket::Receive(TDes8& aReceiveBuffer, TRequestStatus& aStatus) { WSP_LOG(WspLog::Printf(_L("RWin32Socket::Receive: this: 0x%x, bytes to receive: %d"), this, aReceiveBuffer.Length())); iWin32Message.Set(CWin32Socket::EReceive, aReceiveBuffer, aStatus); return MakeRequest(iWin32Message); }