From 1cd2a51a135eec42f70724e6e8da0eecc7050ffc Mon Sep 17 00:00:00 2001 From: micio Date: Tue, 6 Aug 2013 21:15:51 +0000 Subject: [PATCH] Examples/SkylarkUpload : avoid unneeded session savings during progress callback git-svn-id: svn://ultimatepp.org/upp/trunk@6233 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- examples/SkylarkUpload/Handlers.icpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/examples/SkylarkUpload/Handlers.icpp b/examples/SkylarkUpload/Handlers.icpp index e10a969ac..3aa819b62 100644 --- a/examples/SkylarkUpload/Handlers.icpp +++ b/examples/SkylarkUpload/Handlers.icpp @@ -24,10 +24,15 @@ int ProgressHandler(int reason, Http &http, int size) // reading contents ? case PROGRESS_CONTENT: { + int oldPercent = http[currentId]; + int total = http[totalId]; + + // take care to NOT return 100% up to upload ended really + int percent = min(99, (int)(100.0 * size / total)); + // avoid unnnedded session storing - int oldCurrent = http[currentId]; - if(oldCurrent != size) - http.SessionSet(currentId, size); + if(oldPercent != percent) + http.SessionSet(currentId, percent); break; } @@ -47,12 +52,8 @@ int ProgressHandler(int reason, Http &http, int size) if(!IsNull(total)) { if(total) - { // if upload not ended, return the progress % - // take care to NOT return 100% up to upload ended really - int current = http[currentId]; - return min(99, (int)(100.0 * current / total)); - } + return http[currentId]; else { // upload ended, nullify session variables and return 100%