1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-10 20:42:21 +02:00

Curl enhancements

This commit is contained in:
Brian Fiete 2021-08-02 10:43:59 -07:00
parent 954f6312b8
commit 879ac7f989
2 changed files with 25 additions and 2 deletions

View file

@ -917,6 +917,12 @@ namespace CURL
return WrapResult((ReturnCode)curl_easy_setopt(mCURL, (int)option, (int)(void*)val.CStr()));
}
public Result<void, ReturnCode> SetOpt(Option option, StringView val)
{
Debug.Assert((int)option / 10000 == 1);
return WrapResult((ReturnCode)curl_easy_setopt(mCURL, (int)option, (int)(void*)scope String(4096)..Append(val).CStr()));
}
public Result<void, ReturnCode> SetOpt(Option option, int val)
{
Debug.Assert(((int)option / 10000 == 0) || ((int)option / 10000 == 3));

View file

@ -8,7 +8,8 @@ namespace CURL
{
class Transfer
{
CURL.Easy mCurl = new CURL.Easy() ~ delete _;
CURL.Easy mCurl;
bool mOwns;
bool mCancelling = false;
List<uint8> mData = new List<uint8>() ~ delete _;
Stopwatch mStatsTimer = new Stopwatch() ~ delete _;
@ -59,7 +60,13 @@ namespace CURL
public this()
{
mCurl = new CURL.Easy();
mOwns = true;
}
public this(CURL.Easy curl)
{
mCurl = curl;
}
public ~this()
@ -67,6 +74,9 @@ namespace CURL
mCancelling = true;
if (mRunning)
mDoneEvent.WaitFor();
if (mOwns)
delete mCurl;
}
int GetCurBytesPerSecond()
@ -119,7 +129,7 @@ namespace CURL
return count;
}
public void Init(String url)
public void Init(StringView url)
{
function int(void *p, int dltotal, int dlnow, int ultotal, int ulnow) callback = => Callback;
mCurl.SetOptFunc(.XferInfoFunction, (void*)callback);
@ -133,6 +143,13 @@ namespace CURL
mCurl.SetOpt(.URL, url);
mCurl.SetOpt(.NoProgress, false);
mCurl.SetOpt(.IPResolve, (int)CURL.Easy.IPResolve.V4);
mCurl.SetOpt(.HTTPGet, true);
}
public void InitPost(String url, String param)
{
Init(url);
mCurl.SetOpt(.Postfields, param);
}
public Result<Span<uint8>> Perform()