From 12535ec1f9296da27977ba8b07a2a53a519ddd85 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Sat, 24 Mar 2007 14:20:20 +0000 Subject: [PATCH] error checking :) --- qw/source/cl_http.c | 20 +++++++++++++++++--- qw/source/cl_parse.c | 17 ++++++++++++++++- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/qw/source/cl_http.c b/qw/source/cl_http.c index 5791768b6..f13ecc9b0 100644 --- a/qw/source/cl_http.c +++ b/qw/source/cl_http.c @@ -101,10 +101,24 @@ void CL_HTTP_Update (void) { int running_handles; + int messages_in_queue; + CURLMsg *msg; + curl_multi_perform (multi_handle, &running_handles); - if (!running_handles) { - curl_multi_remove_handle (multi_handle, easy_handle); - CL_FinishDownload (); + while ((msg = curl_multi_info_read (multi_handle, &messages_in_queue))) { + if (msg->msg == CURLMSG_DONE) { + long response_code; + + curl_easy_getinfo (msg->easy_handle, CURLINFO_RESPONSE_CODE, + &response_code); + if (response_code == 200) { + CL_FinishDownload (); + } else { + Con_Printf ("download failed: %ld\n", response_code); + CL_FailDownload (); + } + curl_multi_remove_handle (multi_handle, easy_handle); + } } } diff --git a/qw/source/cl_parse.c b/qw/source/cl_parse.c index 7defbd30d..550c7c3ea 100644 --- a/qw/source/cl_parse.c +++ b/qw/source/cl_parse.c @@ -456,6 +456,19 @@ CL_FinishDownload (void) CL_RequestNextDownload (); } +void +CL_FailDownload (void) +{ + if (cls.download) { + Qclose (cls.download); + cls.download = NULL; + } + dstring_clearstr (cls.downloadname); + dstring_clearstr (cls.downloadtempname); + dstring_clearstr (cls.downloadurl); + CL_RequestNextDownload (); +} + static int CL_OpenDownload (void) { @@ -505,11 +518,12 @@ CL_ParseDownload (void) // read the data size = MSG_ReadShort (net_message); percent = MSG_ReadByte (net_message); -Con_Printf ("%d %d\n", size, percent); + if (cls.demoplayback) { if (size > 0) net_message->readcount += size; dstring_clearstr (cls.downloadname); + dstring_clearstr (cls.downloadtempname); dstring_clearstr (cls.downloadurl); return; // not in demo playback } @@ -522,6 +536,7 @@ Con_Printf ("%d %d\n", size, percent); cls.download = NULL; } dstring_clearstr (cls.downloadname); + dstring_clearstr (cls.downloadtempname); dstring_clearstr (cls.downloadurl); CL_RequestNextDownload (); return;