mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-15 06:44:10 +02:00
Curl enhancements
This commit is contained in:
parent
954f6312b8
commit
879ac7f989
2 changed files with 25 additions and 2 deletions
|
@ -917,6 +917,12 @@ namespace CURL
|
||||||
return WrapResult((ReturnCode)curl_easy_setopt(mCURL, (int)option, (int)(void*)val.CStr()));
|
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)
|
public Result<void, ReturnCode> SetOpt(Option option, int val)
|
||||||
{
|
{
|
||||||
Debug.Assert(((int)option / 10000 == 0) || ((int)option / 10000 == 3));
|
Debug.Assert(((int)option / 10000 == 0) || ((int)option / 10000 == 3));
|
||||||
|
|
|
@ -8,7 +8,8 @@ namespace CURL
|
||||||
{
|
{
|
||||||
class Transfer
|
class Transfer
|
||||||
{
|
{
|
||||||
CURL.Easy mCurl = new CURL.Easy() ~ delete _;
|
CURL.Easy mCurl;
|
||||||
|
bool mOwns;
|
||||||
bool mCancelling = false;
|
bool mCancelling = false;
|
||||||
List<uint8> mData = new List<uint8>() ~ delete _;
|
List<uint8> mData = new List<uint8>() ~ delete _;
|
||||||
Stopwatch mStatsTimer = new Stopwatch() ~ delete _;
|
Stopwatch mStatsTimer = new Stopwatch() ~ delete _;
|
||||||
|
@ -59,7 +60,13 @@ namespace CURL
|
||||||
|
|
||||||
public this()
|
public this()
|
||||||
{
|
{
|
||||||
|
mCurl = new CURL.Easy();
|
||||||
|
mOwns = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public this(CURL.Easy curl)
|
||||||
|
{
|
||||||
|
mCurl = curl;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ~this()
|
public ~this()
|
||||||
|
@ -67,6 +74,9 @@ namespace CURL
|
||||||
mCancelling = true;
|
mCancelling = true;
|
||||||
if (mRunning)
|
if (mRunning)
|
||||||
mDoneEvent.WaitFor();
|
mDoneEvent.WaitFor();
|
||||||
|
|
||||||
|
if (mOwns)
|
||||||
|
delete mCurl;
|
||||||
}
|
}
|
||||||
|
|
||||||
int GetCurBytesPerSecond()
|
int GetCurBytesPerSecond()
|
||||||
|
@ -119,7 +129,7 @@ namespace CURL
|
||||||
return count;
|
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;
|
function int(void *p, int dltotal, int dlnow, int ultotal, int ulnow) callback = => Callback;
|
||||||
mCurl.SetOptFunc(.XferInfoFunction, (void*)callback);
|
mCurl.SetOptFunc(.XferInfoFunction, (void*)callback);
|
||||||
|
@ -133,6 +143,13 @@ namespace CURL
|
||||||
mCurl.SetOpt(.URL, url);
|
mCurl.SetOpt(.URL, url);
|
||||||
mCurl.SetOpt(.NoProgress, false);
|
mCurl.SetOpt(.NoProgress, false);
|
||||||
mCurl.SetOpt(.IPResolve, (int)CURL.Easy.IPResolve.V4);
|
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()
|
public Result<Span<uint8>> Perform()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue