My Project
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | List of all members
ParaEngine::CURLRequestTask Class Reference

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_httppostm_pFormPost
 CURLOPT_HTTPPOST.
 
struct curl_httppostm_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
 

Detailed Description

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.

Member Function Documentation

§ Asset_HTTP_request_callback()

DWORD ParaEngine::CURLRequestTask::Asset_HTTP_request_callback ( int  nResult,
CURLRequestTask pRequest,
LPVOID  lpUserData 
)
static

this function can be used for HTTP texture callback.

see SetAssetRequestOpt.

Parameters
lpUserDatais expected to be CAssetRequestData

§ CompleteTask()

void ParaEngine::CURLRequestTask::CompleteTask ( )

call the call back if any, this function must be called in the main game thread.

§ CUrl_write_data_callback()

size_t ParaEngine::CURLRequestTask::CUrl_write_data_callback ( void *  buffer,
size_t  size,
size_t  nmemb,
void *  stream 
)
static

curl call back.

§ GetTimeOut()

int ParaEngine::CURLRequestTask::GetTimeOut ( )

Get the time out of the request.

default is 15000 milliseconds.

§ IsTimedOut()

bool ParaEngine::CURLRequestTask::IsTimedOut ( DWORD  nCurrentTime)

whether this request is timed out relative to a given time

Parameters
nCurrentTimeit must be a value returned from GetTickCount();

§ SetAssetRequestOpt()

void ParaEngine::CURLRequestTask::SetAssetRequestOpt ( CAssetRequestData pRequestData,
URL_REQUEST_TASK_CALLBACK  pFuncCallback = NULL 
)

set the options for asset request.

Parameters
pRequestDatait must be created using new operator. The ownership of this object is transfered to the request. and the caller should never call the delete.
pFuncCallbackthe call back function to use. if none is specified, it will pick a default one to use according to pRequestData->m_nAssetType;

§ SetCurlEasyOpt()

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.

§ SetTimeOut()

void ParaEngine::CURLRequestTask::SetTimeOut ( int  nMilliSeconds)

set the time out of the request.

default is 15000 milliseconds.

§ UpdateTime()

DWORD ParaEngine::CURLRequestTask::UpdateTime ( )

this is to set the timer to current time.

it is used to check for TimedOut()

Returns
: return the current time.

Member Data Documentation

§ m_nStartTime

DWORD ParaEngine::CURLRequestTask::m_nStartTime

The time that this request is started or received any response.

in milliseconds

§ m_nStatus

URLREQUEST_STATUS ParaEngine::CURLRequestTask::m_nStatus

the current status of the request.

§ m_nTimeOutTime

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.

§ m_nUserDataType

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)

§ m_pfuncCallBack

URL_REQUEST_TASK_CALLBACK ParaEngine::CURLRequestTask::m_pfuncCallBack

the C++ function to call when task is finished.

§ m_sNPLCallback

string ParaEngine::CURLRequestTask::m_sNPLCallback

the NPL function to call when task is finished.


The documentation for this class was generated from the following files: