[GB.NET.CURL]
* NEW: New Progress event raised while the FtpClient is downloading or uploading some data. The event is not raised by the HttpClient yet. * NEW: FtpClient has four new read-only properties to get information on uploading and downloading progress: Downloaded, Uploaded, TotalDownloaded and TotalUploaded. git-svn-id: svn://localhost/gambas/trunk@5663 867c0c6c-44f3-4631-809d-bfa615b0a4ec
This commit is contained in:
parent
2bf1efd58b
commit
3a1b334193
3 changed files with 72 additions and 5 deletions
|
@ -43,6 +43,7 @@ DECLARE_EVENT(EVENT_Finished);
|
|||
DECLARE_EVENT(EVENT_Error);
|
||||
DECLARE_EVENT(EVENT_Connect);
|
||||
DECLARE_EVENT(EVENT_Read);
|
||||
DECLARE_EVENT(EVENT_Progress);
|
||||
|
||||
static CCURL *_async_list = NULL;
|
||||
|
||||
|
@ -251,6 +252,18 @@ void CURL_init_stream(void *_object)
|
|||
GB.Stream.SetAvailableNow(&THIS->stream, TRUE);
|
||||
}
|
||||
|
||||
|
||||
static int curl_progress(void *_object, double dltotal, double dlnow, double ultotal, double ulnow)
|
||||
{
|
||||
THIS->dltotal = (int64_t)dltotal;
|
||||
THIS->dlnow = (int64_t)dlnow;
|
||||
THIS->ultotal = (int64_t)ultotal;
|
||||
THIS->ulnow = (int64_t)ulnow;
|
||||
GB.Raise(THIS, EVENT_Progress, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/***************************************************************
|
||||
This CallBack is called each event loop by Gambas to test
|
||||
the status of curl descriptors
|
||||
|
@ -364,6 +377,20 @@ bool CURL_check_active(void *_object)
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
void CURL_set_progress(void *_object, bool progress)
|
||||
{
|
||||
curl_easy_setopt(THIS_CURL, CURLOPT_NOPROGRESS, progress ? 0 : 1);
|
||||
if (progress)
|
||||
{
|
||||
curl_easy_setopt(THIS_CURL, CURLOPT_PROGRESSFUNCTION , curl_progress);
|
||||
curl_easy_setopt(THIS_CURL, CURLOPT_PROGRESSDATA , _object);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
|
||||
BEGIN_PROPERTY(Curl_User)
|
||||
|
||||
if (READ_PROPERTY)
|
||||
|
@ -575,6 +602,30 @@ BEGIN_PROPERTY(Curl_Debug)
|
|||
|
||||
END_PROPERTY
|
||||
|
||||
BEGIN_PROPERTY(Curl_Downloaded)
|
||||
|
||||
GB.ReturnLong(THIS->dlnow);
|
||||
|
||||
END_PROPERTY
|
||||
|
||||
BEGIN_PROPERTY(Curl_Uploaded)
|
||||
|
||||
GB.ReturnLong(THIS->ulnow);
|
||||
|
||||
END_PROPERTY
|
||||
|
||||
BEGIN_PROPERTY(Curl_TotalDownloaded)
|
||||
|
||||
GB.ReturnLong(THIS->dltotal);
|
||||
|
||||
END_PROPERTY
|
||||
|
||||
BEGIN_PROPERTY(Curl_TotalUploaded)
|
||||
|
||||
GB.ReturnLong(THIS->ultotal);
|
||||
|
||||
END_PROPERTY
|
||||
|
||||
//*************************************************************************
|
||||
//#################### GAMBAS INTERFACE ###################################
|
||||
//*************************************************************************
|
||||
|
@ -601,10 +652,16 @@ GB_DESC CCurlDesc[] =
|
|||
GB_PROPERTY_READ("ErrorText", "s", Curl_ErrorText),
|
||||
GB_PROPERTY("Debug", "b", Curl_Debug),
|
||||
|
||||
GB_PROPERTY_READ("Downloaded", "l", Curl_Downloaded),
|
||||
GB_PROPERTY_READ("Uploaded", "l", Curl_Uploaded),
|
||||
GB_PROPERTY_READ("TotalDownloaded", "l", Curl_TotalDownloaded),
|
||||
GB_PROPERTY_READ("TotalUploaded", "l", Curl_TotalUploaded),
|
||||
|
||||
GB_EVENT("Finished", NULL, NULL, &EVENT_Finished),
|
||||
GB_EVENT("Connect", NULL, NULL, &EVENT_Connect),
|
||||
GB_EVENT("Read", NULL, NULL, &EVENT_Read),
|
||||
GB_EVENT("Error", NULL, NULL, &EVENT_Error),
|
||||
GB_EVENT("Progress", NULL, NULL, &EVENT_Progress),
|
||||
|
||||
GB_END_DECLARE
|
||||
};
|
||||
|
|
|
@ -68,6 +68,10 @@ typedef
|
|||
int timeout;
|
||||
int method; // 0->Get, 1->Put
|
||||
char *data;
|
||||
int64_t dltotal;
|
||||
int64_t dlnow;
|
||||
int64_t ultotal;
|
||||
int64_t ulnow;
|
||||
unsigned async : 1;
|
||||
unsigned in_list : 1;
|
||||
unsigned debug : 1;
|
||||
|
@ -102,4 +106,6 @@ void CURL_init_stream(void *_object);
|
|||
|
||||
bool CURL_check_active(void *_object);
|
||||
|
||||
void CURL_set_progress(void *_object, bool progress);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -43,7 +43,7 @@
|
|||
#define EXEC_CMD 2
|
||||
|
||||
|
||||
static int ftp_read_curl (void *buffer, size_t size, size_t nmemb, void *_object)
|
||||
static int ftp_read_curl(void *buffer, size_t size, size_t nmemb, void *_object)
|
||||
{
|
||||
FILE *file = THIS_FILE;
|
||||
THIS_STATUS = NET_RECEIVING_DATA;
|
||||
|
@ -80,11 +80,11 @@ static int ftp_write_curl(void *buffer, size_t size, size_t nmemb, void *_object
|
|||
return nmemb;
|
||||
}
|
||||
|
||||
|
||||
static void ftp_reset(void *_object)
|
||||
{
|
||||
GB.FreeString(&THIS->data);
|
||||
GB.Unref(&THIS_FTP->commands);
|
||||
CURL_set_progress(THIS_CURL, FALSE);
|
||||
}
|
||||
|
||||
|
||||
|
@ -112,13 +112,13 @@ static void ftp_initialize_curl_handle(void *_object)
|
|||
|
||||
if (!THIS->async)
|
||||
{
|
||||
curl_easy_setopt(THIS_CURL, CURLOPT_NOSIGNAL,1);
|
||||
curl_easy_setopt(THIS_CURL, CURLOPT_TIMEOUT,THIS->timeout);
|
||||
curl_easy_setopt(THIS_CURL, CURLOPT_NOSIGNAL, 1);
|
||||
curl_easy_setopt(THIS_CURL, CURLOPT_TIMEOUT, THIS->timeout);
|
||||
}
|
||||
|
||||
curl_easy_setopt(THIS_CURL, CURLOPT_VERBOSE, (bool)THIS->debug);
|
||||
curl_easy_setopt(THIS_CURL, CURLOPT_PRIVATE,(char*)_object);
|
||||
|
||||
|
||||
CURL_proxy_set(&THIS->proxy.proxy,THIS_CURL);
|
||||
CURL_user_set(&THIS->user, THIS_CURL);
|
||||
curl_easy_setopt(THIS_CURL, CURLOPT_URL,THIS_URL);
|
||||
|
@ -150,6 +150,8 @@ static int ftp_exec(void *_object, int what, GB_ARRAY commands)
|
|||
curl_easy_setopt(THIS_CURL, CURLOPT_WRITEDATA , _object);
|
||||
curl_easy_setopt(THIS_CURL, CURLOPT_UPLOAD , 0);
|
||||
|
||||
CURL_set_progress(THIS_CURL, TRUE);
|
||||
|
||||
break;
|
||||
|
||||
case EXEC_PUT:
|
||||
|
@ -158,6 +160,8 @@ static int ftp_exec(void *_object, int what, GB_ARRAY commands)
|
|||
curl_easy_setopt(THIS_CURL, CURLOPT_READDATA , _object);
|
||||
curl_easy_setopt(THIS_CURL, CURLOPT_UPLOAD , 1);
|
||||
|
||||
CURL_set_progress(THIS_CURL, TRUE);
|
||||
|
||||
break;
|
||||
|
||||
case EXEC_CMD:
|
||||
|
|
Loading…
Reference in a new issue