My Project
|
URL request can be a HTTP get/post request etc. More...
#include <NPLNetClient.h>
Public Types | |
enum | URLREQUEST_TYPE { URL_REQUEST_HTTP_AUTO, URL_REQUEST_HTTP_GET, URL_REQUEST_HTTP_POST, URL_REQUEST_HTTP_GETFILE } |
type of the url request task | |
enum | URLREQUEST_STATUS { URL_REQUEST_UNSTARTED, URL_REQUEST_INCOMPLETE, URL_REQUEST_COMPLETED } |
url request status | |
Public Member Functions | |
CURLFORMcode | AppendFormParam (const char *name, const char *value) |
append form parameters | |
CURLFORMcode | AppendFormParam (const char *name, const char *type, const char *file, const char *data, int datalen) |
append a file, such as {name = {file="/tmp/test.txt", type="text/plain"}} {name = {file="dummy.html", data="<html><bold>bold</bold></html>, type="text/html"}} input can be NULL if not available. | |
void | SetCurlEasyOpt (CURL *handle) |
init the easy handle according to the settings. More... | |
void | CompleteTask () |
call the call back if any, this function must be called in the main game thread. More... | |
void | SetTimeOut (int nMilliSeconds) |
set the time out of the request. More... | |
int | GetTimeOut () |
Get the time out of the request. More... | |
void | SetAssetRequestOpt (CAssetRequestData *pRequestData, URL_REQUEST_TASK_CALLBACK pFuncCallback=NULL) |
set the options for asset request. More... | |
void | SafeDeleteUserData () |
safe delete user data | |
bool | IsTimedOut (DWORD nCurrentTime) |
whether this request is timed out relative to a given time More... | |
DWORD | UpdateTime () |
this is to set the timer to current time. More... | |
Static Public Member Functions | |
static size_t | CUrl_write_data_callback (void *buffer, size_t size, size_t nmemb, void *stream) |
curl call back. More... | |
static size_t | CUrl_write_header_callback (void *buffer, size_t size, size_t nmemb, void *stream) |
static DWORD | Asset_HTTP_request_callback (int nResult, CURLRequestTask *pRequest, LPVOID lpUserData) |
this function can be used for HTTP texture callback. More... | |
Public Attributes | |
string | m_url |
CURLOPT_URL. | |
struct curl_httppost * | m_pFormPost |
CURLOPT_HTTPPOST. | |
struct curl_httppost * | m_pFormLast |
int | m_nPriority |
task priority | |
string | m_sNPLCallback |
the NPL function to call when task is finished. More... | |
URL_REQUEST_TASK_CALLBACK | m_pfuncCallBack |
the C++ function to call when task is finished. More... | |
string | m_sSaveToFileName |
the file name to save the response data to | |
int | m_nUserDataType |
default to 0. More... | |
union { | |
LPVOID m_pUserData | |
CAssetRequestData * m_pAssetData | |
}; | |
optional user data to be send along with the m_pfuncCallBack | |
URLREQUEST_TYPE | m_type |
The type of the url request task. | |
URLREQUEST_STATUS | m_nStatus |
the current status of the request. More... | |
DWORD | m_nStartTime |
The time that this request is started or received any response. More... | |
DWORD | m_nTimeOutTime |
for how long the request is considered timed out. More... | |
int | m_nBytesReceived |
int | m_nTotalBytes |
vector< char > | m_data |
vector< char > | m_header |
string | m_sResponseData |
string | m_sResponseHeader |
CURLcode | m_returnCode |
long | m_responseCode |
Static Public Attributes | |
static const DWORD | DEFAULT_TIME_OUT = 15000 |
URL request can be a HTTP get/post request etc.
note: Only create an instance of this class using the new operator. CURLRequest can be inserted to a task pool for processing.
|
static |
this function can be used for HTTP texture callback.
see SetAssetRequestOpt.
lpUserData | is expected to be CAssetRequestData |
void ParaEngine::CURLRequestTask::CompleteTask | ( | ) |
call the call back if any, this function must be called in the main game thread.
|
static |
curl call back.
int ParaEngine::CURLRequestTask::GetTimeOut | ( | ) |
Get the time out of the request.
default is 15000 milliseconds.
bool ParaEngine::CURLRequestTask::IsTimedOut | ( | DWORD | nCurrentTime | ) |
whether this request is timed out relative to a given time
nCurrentTime | it must be a value returned from GetTickCount(); |
void ParaEngine::CURLRequestTask::SetAssetRequestOpt | ( | CAssetRequestData * | pRequestData, |
URL_REQUEST_TASK_CALLBACK | pFuncCallback = NULL |
||
) |
set the options for asset request.
pRequestData | it must be created using new operator. The ownership of this object is transfered to the request. and the caller should never call the delete. |
pFuncCallback | the call back function to use. if none is specified, it will pick a default one to use according to pRequestData->m_nAssetType; |
void ParaEngine::CURLRequestTask::SetCurlEasyOpt | ( | CURL * | handle | ) |
init the easy handle according to the settings.
It will also prepare the task for the curl interface by clearing data, etc.
void ParaEngine::CURLRequestTask::SetTimeOut | ( | int | nMilliSeconds | ) |
set the time out of the request.
default is 15000 milliseconds.
DWORD ParaEngine::CURLRequestTask::UpdateTime | ( | ) |
this is to set the timer to current time.
it is used to check for TimedOut()
DWORD ParaEngine::CURLRequestTask::m_nStartTime |
The time that this request is started or received any response.
in milliseconds
URLREQUEST_STATUS ParaEngine::CURLRequestTask::m_nStatus |
the current status of the request.
DWORD ParaEngine::CURLRequestTask::m_nTimeOutTime |
for how long the request is considered timed out.
If a request was not responding, either because of DNS resolving timeout or connection timed out. we will manually remove the request and free the slot for next request. This is usually not needed. However, in windows vista, DNS time out is not working as expected, in windows XP the libcurl can detect time out by itself.
int ParaEngine::CURLRequestTask::m_nUserDataType |
default to 0.
if 0, the request will not SAFE_DELETE the user data. the caller is responsible for the task. if it is 1, the destructor will try to SAFE_DELETE(m_pAssetData)
URL_REQUEST_TASK_CALLBACK ParaEngine::CURLRequestTask::m_pfuncCallBack |
the C++ function to call when task is finished.
string ParaEngine::CURLRequestTask::m_sNPLCallback |
the NPL function to call when task is finished.