From: Jay Freeman (saurik) Date: Tue, 26 Feb 2008 11:25:49 +0000 (+0000) Subject: Added some better error checking to the new CFNetwork APT backend. X-Git-Url: https://git.saurik.com/apt-legacy.git/commitdiff_plain/910f26ec9bc823391d069d92b7943aeb653acd96?ds=inline Added some better error checking to the new CFNetwork APT backend. M cfnetwork.diff git-svn-id: http://svn.telesphoreo.org/trunk@105 514c082c-b64e-11dc-b46d-3d985efe055d --- diff --git a/methods/http.cc b/methods/http.cc index 7e5bbc9..012d450 100644 --- a/methods/http.cc +++ b/methods/http.cc @@ -1102,24 +1102,32 @@ int HttpMethod::Loop() URI uri = Queue->Uri; + FetchResult Res; + + uint8_t data[10240]; + size_t offset = 0; + Status("Connecting to %s", uri.Host.c_str()); if (!CFReadStreamOpen(rs)) { + _error->Error("Unable to open stream"); Fail(true); - continue; + goto done; } - uint8_t data[10240]; CFIndex rd = CFReadStreamRead(rs, data, sizeof(data)); - FetchResult Res; + if (rd == -1) { + _error->Error("Stream read failure"); + Fail(true); + goto done; + } + Res.Filename = Queue->DestFile; hm = (CFHTTPMessageRef) CFReadStreamCopyProperty(rs, kCFStreamPropertyHTTPResponseHeader); UInt32 sc = CFHTTPMessageGetResponseStatusCode(hm); - size_t offset = 0; - sr = CFHTTPMessageCopyHeaderFieldValue(hm, CFSTR("Content-Range")); if (sr != NULL) { size_t ln = CFStringGetLength(sr) + 1; @@ -1215,9 +1223,10 @@ int HttpMethod::Loop() URIStart(Res); - read: if (rd == -1) + read: if (rd == -1) { + _error->Error("Stream read failure"); Fail(true); - else if (rd == 0) { + } else if (rd == 0) { if (Res.Size == 0) Res.Size = File->Size(); diff --git a/methods/http.cc.orig b/methods/http.cc.orig index 4043eb1..b53b5da 100644 --- a/methods/http.cc.orig +++ b/methods/http.cc.orig @@ -1098,24 +1098,32 @@ int HttpMethod::Loop() URI uri = Queue->Uri; + FetchResult Res; + + uint8_t data[10240]; + size_t offset = 0; + Status("Connecting to %s", uri.Host.c_str()); if (!CFReadStreamOpen(rs)) { + _error->Error("Unable to open stream"); Fail(true); - continue; + goto done; } - uint8_t data[10240]; CFIndex rd = CFReadStreamRead(rs, data, sizeof(data)); - FetchResult Res; + if (rd == -1) { + _error->Error("Stream read failure"); + Fail(true); + goto done; + } + Res.Filename = Queue->DestFile; hm = (CFHTTPMessageRef) CFReadStreamCopyProperty(rs, kCFStreamPropertyHTTPResponseHeader); UInt32 sc = CFHTTPMessageGetResponseStatusCode(hm); - size_t offset = 0; - sr = CFHTTPMessageCopyHeaderFieldValue(hm, CFSTR("Content-Range")); if (sr != NULL) { size_t ln = CFStringGetLength(sr) + 1; @@ -1211,9 +1219,10 @@ int HttpMethod::Loop() URIStart(Res); - read: if (rd == -1) + read: if (rd == -1) { + _error->Error("Stream read failure"); Fail(true); - else if (rd == 0) { + } else if (rd == 0) { if (Res.Size == 0) Res.Size = File->Size();