From 5aac462be08dda22bdcf48e8458fcc61a4befa6b Mon Sep 17 00:00:00 2001 From: Ken Sanislo Date: Wed, 3 Feb 2016 18:40:13 -0800 Subject: [PATCH] pass httpcReceiveData's return back through httpcDownloadData --- libctru/source/services/httpc.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/libctru/source/services/httpc.c b/libctru/source/services/httpc.c index f4e9325..1750fd0 100644 --- a/libctru/source/services/httpc.c +++ b/libctru/source/services/httpc.c @@ -1,3 +1,8 @@ +//#include +//#include +//#include +//#include <3ds.h> + #include #include <3ds/types.h> #include <3ds/result.h> @@ -113,6 +118,7 @@ Result httpcGetResponseStatusCode(httpcContext *context, u32* out, u64 delay) Result httpcDownloadData(httpcContext *context, u8* buffer, u32 size, u32 *downloadedsize) { Result ret=0; + Result dlret=HTTPC_RESULTCODE_DOWNLOADPENDING; u32 pos=0, sz=0; u32 dlstartpos=0; u32 dlpos=0; @@ -122,12 +128,11 @@ Result httpcDownloadData(httpcContext *context, u8* buffer, u32 size, u32 *downl ret=httpcGetDownloadSizeState(context, &dlstartpos, NULL); if(R_FAILED(ret))return ret; - while(pos < size) + while(pos < size && dlret==HTTPC_RESULTCODE_DOWNLOADPENDING) { sz = size - pos; - ret=httpcReceiveData(context, &buffer[pos], sz); - if(ret!=HTTPC_RESULTCODE_DOWNLOADPENDING)break; + dlret=httpcReceiveData(context, &buffer[pos], sz); ret=httpcGetDownloadSizeState(context, &dlpos, NULL); if(R_FAILED(ret))return ret; @@ -135,15 +140,9 @@ Result httpcDownloadData(httpcContext *context, u8* buffer, u32 size, u32 *downl pos = dlpos - dlstartpos; } - // This duplication is awful, but if I reorder the loop to avoid it - // then I get failure returns from httpcReceiveData()... wtf? - ret=httpcGetDownloadSizeState(context, &dlpos, NULL); - if(R_FAILED(ret))return ret; - pos = dlpos - dlstartpos; - if(downloadedsize)*downloadedsize = pos; - return ret; + return dlret; } Result HTTPC_Initialize(Handle handle)