Comments (8)
The OnPerformCallback
will be called when the request is finished which also means the Lib.curl_multi_info_read
returns DONE
underhood.
If the link you request never ends, such as a living stream, then the OnPerformCallback
might not have a chance to be called. If so you could consider to use ProgressCallback
instead.
Beside, when the CurlEasy reqeust was going to callback it would put it into a TaskScheduler
which belongs to the thread where the Perform
was called. That means if you didn't perform this request on the Unity main thread the callback might not be called. If so I will mark this issue as a bug and find a way to handle it.
BTW, if you could provide a simple project to reproduce this issue would be much great helpful.
from curl-unity.
Thanks for the quick reply!
Carving out a 'simple' project is a bit hard since I need LoginWithAmazon and even a bunch more stood up to support creating a DownChannel with AVS.
Using the ProgressCallback
makes sense. When I added that to my Easy declaration, the function is basically called continuously, so I created this function:
public void DownChannelProgressCallback(long dltotal, long dlnow, long ultotal, long ulnow, CurlEasy easy)
{
// We're in downchannel callback, meaning we've either received a directive or a disconnect
// A directive?
if(easy.inText != null || easy.message != null || easy.outText != null)
{
Debug.Log("=========== In downchannel progress callback. ===========");
Debug.Log(easy.inData);
Debug.Log(easy.outData);
Debug.Log(easy.inText);
Debug.Log(easy.outText);
Debug.Log(easy.contentType);
Debug.Log(easy.message);
Debug.Log($"Download - Total: {dltotal}; Now: {dlnow};");
Debug.Log($"Upload - Total: {ultotal}; Now: {ulnow};");
easy.Abort();
}
}
However, this never prints anything. Any thoughts there? Am I looking in the right place? Am I handling the response correctly?
from curl-unity.
The inText
will be available after the request is finised so does the message
. The outText
was the data you put into the request and in the code you provided it seems to be empty.
If you just want the response headers, without any response body, you may try to set the method
to HEAD
such as:
var easy = new CurlEasy();
easy.method = "HEAD";
Then this request will auto abort after all the headers retrieved.
If the server doesn't accept the HEAD method then you could try to use the default GET instead and set the option CURLOPT.NOBODY to true:
easy.SetOpt(CURLOPT.NOBODY, true);
from curl-unity.
The directives endpoint has no body, so it makes sense that it's empty.
But I want the response body as well. Let me try the CURLOPT setting.
from curl-unity.
If you want the response body you should wait the request to finish.
If you really want to access incoming data before it finishes you could take a look at the private member responseBodyStream
of CurlEasy which holds the unfinished incoming data. Just be careful this stream is being writing on other thread than the Unity main thread.
from curl-unity.
That makes sense, but the directives endpoint is designed to never close (unless you close it). I'll look at the responseBodyStream.
from curl-unity.
That did it!
I changed responseBodyStream to public and then do this in my ProgressCallback:
public void DownChannelProgressCallback(long dltotal, long dlnow, long ultotal, long ulnow, CurlEasy easy)
{
// We're in downchannel callback, meaning we've either received a directive or a disconnect
// A directive?
var ms = easy.responseBodyStream as MemoryStream;
// Parse data in the stream
byte[] inData = ms.ToArray();
if (inData.Length > 0)
{
Debug.Log("========== In the DownChannel! ==========");
Debug.Log(Encoding.UTF8.GetString(inData));
// Clear out the stream
easy.responseBodyStream = new MemoryStream();
}
}
Any idea if there's a better way to implement this? I'm worried a bit about obliterating a message when I clear responseBodyStream. I'm also wondering if I should use a Coroutine or task to periodically query the responseBodyStream rather than the progressCallback, which seems to fire continuously.
from curl-unity.
Yes you could access the stream in a coroutine if you make it thread safe, such as by adding some necessary locks.
In my opinion the most handy way is to make your own duplex steam which support reading and writing at the same time. And since you are reading an endless stream it is not wise to use a memory stream because it may cause an out of memory issue.
You should consider to use a file stream or a ring buffer.
from curl-unity.
Related Issues (13)
- 运行失败 HOT 1
- 请问怎么在下载进行中修改限速呢?直接设置SetOpt编辑器好用,安卓真机不好用 HOT 4
- CurlEasy.cs 里 ProgressFunction的参数类型是否应该是long? HOT 2
- 关于使用CurlMulti多线程下载的问题 HOT 2
- CurlMulti可能会有多线程导致崩溃的问题? HOT 8
- 设置最大下载速度接口在Android模拟器上无效
- PC端正常运行 ,android端运行异常 HOT 5
- xcode build报错 HOT 4
- Update curl to 7.64.1 HOT 8
- armeabi-v7a Android device CURLOPT_HEADERFUNCTION failed. HOT 4
- Send continuous stream to endpoint HOT 3
- 例子ResumeDownload.cs里,rangeEnd范围好像写错了,多了1byte HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from curl-unity.