Tweaks to make HTTP requests work with HashLink

This commit is contained in:
m0rkeulv
2019-09-10 13:14:24 +02:00
committed by Joshua Granick
parent 1999005e98
commit 0374c62691
2 changed files with 19 additions and 13 deletions

View File

@@ -37,7 +37,7 @@ class NativeHTTPRequest
private static var multiProgressTimer:Timer; private static var multiProgressTimer:Timer;
private static var multiThreadPool:ThreadPool; private static var multiThreadPool:ThreadPool;
private static var multiThreadPoolRunning:Bool; private static var multiThreadPoolRunning:Bool;
#if (cpp || neko) #if (cpp || neko || hl)
private static var multiAddHandle:Deque<CURL>; private static var multiAddHandle:Deque<CURL>;
#end #end
@@ -299,7 +299,7 @@ class NativeHTTPRequest
activeInstances.push(this); activeInstances.push(this);
multiInstances.set(curl, this); multiInstances.set(curl, this);
#if (cpp || neko) #if (cpp || neko || hl)
if (multiAddHandle == null) multiAddHandle = new Deque<CURL>(); if (multiAddHandle == null) multiAddHandle = new Deque<CURL>();
multiAddHandle.add(curl); multiAddHandle.add(curl);
#end #end
@@ -374,20 +374,19 @@ class NativeHTTPRequest
} }
} }
private function curl_onProgress(curl:CURL, dltotal:Int, dlnow:Int, uptotal:Int, upnow:Int):Int private function curl_onProgress(curl:CURL, dltotal:Float, dlnow:Float, uptotal:Float, upnow:Float):Void
{ {
if (upnow > writeBytesLoaded || dlnow > writeBytesLoaded || uptotal > writeBytesTotal || dltotal > writeBytesTotal) if (upnow > writeBytesLoaded || dlnow > writeBytesLoaded || uptotal > writeBytesTotal || dltotal > writeBytesTotal)
{ {
if (upnow > writeBytesLoaded) writeBytesLoaded = upnow; if (upnow > writeBytesLoaded) writeBytesLoaded = Std.int(upnow);
if (dlnow > writeBytesLoaded) writeBytesLoaded = dlnow; if (dlnow > writeBytesLoaded) writeBytesLoaded = Std.int(dlnow);
if (uptotal > writeBytesTotal) writeBytesTotal = uptotal; if (uptotal > writeBytesTotal) writeBytesTotal = Std.int(uptotal);
if (dltotal > writeBytesTotal) writeBytesTotal = dltotal; if (dltotal > writeBytesTotal) writeBytesTotal = Std.int(dltotal);
// Wrong thread // Wrong thread
// promise.progress (bytesLoaded, bytesTotal); // promise.progress (bytesLoaded, bytesTotal);
} }
return 0;
} }
private function curl_onWrite(curl:CURL, output:Bytes):Int private function curl_onWrite(curl:CURL, output:Bytes):Int
@@ -497,7 +496,7 @@ class NativeHTTPRequest
{ {
while (true) while (true)
{ {
#if (cpp || neko) #if (cpp || neko || hl)
var curl = multiAddHandle.pop(false); var curl = multiAddHandle.pop(false);
if (curl != null) multi.addHandle(curl); if (curl != null) multi.addHandle(curl);
#end #end
@@ -532,7 +531,7 @@ class NativeHTTPRequest
private static function multiThreadPool_onComplete(_):Void private static function multiThreadPool_onComplete(_):Void
{ {
#if (cpp || neko) #if (cpp || neko || hl)
var curl = multiAddHandle.pop(false); var curl = multiAddHandle.pop(false);
if (curl != null) if (curl != null)

View File

@@ -159,14 +159,21 @@ class CURL
case CURLOption.XFERINFOFUNCTION: case CURLOption.XFERINFOFUNCTION:
var callback:CURL->Int->Int->Int->Int->Int = cast parameter; var callback:CURL->Int->Int->Int->Int->Int = cast parameter;
parameter = function(dltotal:Int, dlnow:Int, ultotal:Int, ulnow:Int) parameter = function(dltotal:Int, dlnow:Int, ultotal:Int, ulnow:Int):Int
{ {
return callback(this, dltotal, dlnow, ultotal, ulnow); return callback(this, dltotal, dlnow, ultotal, ulnow);
} }
case CURLOption.WRITEFUNCTION: case CURLOption.WRITEFUNCTION:
var callback:CURL->Bytes->Int = cast parameter; var callback:CURL->Bytes->Int = cast parameter;
parameter = function(bytes:Bytes, length:Int) #if hl
parameter = function(bytes:Bytes):Int
{
var read = callback(this, bytes);
return read;
}
#else
parameter = function(bytes:Bytes, length:Int):Int
{ {
var cacheLength = bytes.length; var cacheLength = bytes.length;
@:privateAccess bytes.length = length; @:privateAccess bytes.length = length;
@@ -174,7 +181,7 @@ class CURL
@:privateAccess bytes.length = cacheLength; @:privateAccess bytes.length = cacheLength;
return read; return read;
} }
#end
bytes = Bytes.alloc(0); bytes = Bytes.alloc(0);
// case CURLOption.READFUNCTION: // case CURLOption.READFUNCTION: