diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2020-07-26 14:31:22 +0300 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2020-07-26 14:31:22 +0300 |
commit | c8a7d28f61ab53d841efe38ddcf34be0db3104d9 (patch) | |
tree | 8bc82f27b78ca48cdddfe39747856e82b81987ba /src/gmrequest.c | |
parent | dd4c7ce2e7c55098a90e5b8a265299d10bd52cef (diff) |
GmRequest: Tweaking cancel behavior
Diffstat (limited to 'src/gmrequest.c')
-rw-r--r-- | src/gmrequest.c | 38 |
1 files changed, 16 insertions, 22 deletions
diff --git a/src/gmrequest.c b/src/gmrequest.c index 6f2c2bc5..e05679bd 100644 --- a/src/gmrequest.c +++ b/src/gmrequest.c | |||
@@ -48,21 +48,24 @@ void init_GmRequest(iGmRequest *d) { | |||
48 | } | 48 | } |
49 | 49 | ||
50 | void deinit_GmRequest(iGmRequest *d) { | 50 | void deinit_GmRequest(iGmRequest *d) { |
51 | if (d->req) { | ||
52 | iDisconnectObject(TlsRequest, d->req, readyRead, d); | ||
53 | iDisconnectObject(TlsRequest, d->req, finished, d); | ||
54 | } | ||
51 | lock_Mutex(&d->mutex); | 55 | lock_Mutex(&d->mutex); |
52 | if (d->timeoutId) { | 56 | if (d->timeoutId) { |
53 | SDL_RemoveTimer(d->timeoutId); | 57 | SDL_RemoveTimer(d->timeoutId); |
54 | } | 58 | } |
55 | if (d->req) { | 59 | if (!isFinished_GmRequest(d)) { |
56 | if (!isFinished_GmRequest(d)) { | 60 | unlock_Mutex(&d->mutex); |
57 | iDisconnectObject(TlsRequest, d->req, readyRead, d); | 61 | cancel_TlsRequest(d->req); |
58 | iDisconnectObject(TlsRequest, d->req, finished, d); | 62 | d->state = finished_GmRequestState; |
59 | cancel_TlsRequest(d->req); | ||
60 | d->state = finished_GmRequestState; | ||
61 | } | ||
62 | iRelease(d->req); | ||
63 | d->req = NULL; | ||
64 | } | 63 | } |
65 | unlock_Mutex(&d->mutex); | 64 | else { |
65 | unlock_Mutex(&d->mutex); | ||
66 | } | ||
67 | iRelease(d->req); | ||
68 | d->req = NULL; | ||
66 | delete_Audience(d->finished); | 69 | delete_Audience(d->finished); |
67 | delete_Audience(d->updated); | 70 | delete_Audience(d->updated); |
68 | deinit_Block(&d->body); | 71 | deinit_Block(&d->body); |
@@ -157,8 +160,8 @@ static void requestFinished_GmRequest_(iAnyObject *obj) { | |||
157 | } | 160 | } |
158 | SDL_RemoveTimer(d->timeoutId); | 161 | SDL_RemoveTimer(d->timeoutId); |
159 | d->timeoutId = 0; | 162 | d->timeoutId = 0; |
160 | iReleaseLater(d->req); | 163 | // iReleaseLater(d->req); |
161 | d->req = NULL; | 164 | // d->req = NULL; |
162 | d->state = finished_GmRequestState; | 165 | d->state = finished_GmRequestState; |
163 | unlock_Mutex(&d->mutex); | 166 | unlock_Mutex(&d->mutex); |
164 | iNotifyAudience(d, finished, GmRequestFinished); | 167 | iNotifyAudience(d, finished, GmRequestFinished); |
@@ -186,6 +189,7 @@ void submit_GmRequest(iGmRequest *d) { | |||
186 | } | 189 | } |
187 | else { | 190 | else { |
188 | d->code = failedToOpenFile_GmStatusCode; | 191 | d->code = failedToOpenFile_GmStatusCode; |
192 | setCStr_String(&d->header, cstr_String(path)); | ||
189 | } | 193 | } |
190 | iRelease(f); | 194 | iRelease(f); |
191 | d->state = finished_GmRequestState; | 195 | d->state = finished_GmRequestState; |
@@ -212,16 +216,6 @@ iBool isFinished_GmRequest(const iGmRequest *d) { | |||
212 | return done; | 216 | return done; |
213 | } | 217 | } |
214 | 218 | ||
215 | const char *error_GmRequest(const iGmRequest *d) { | ||
216 | if (d->code == failedToOpenFile_GmStatusCode) { | ||
217 | return "Failed to open file"; | ||
218 | } | ||
219 | if (d->code == invalidHeader_GmStatusCode) { | ||
220 | return "Received invalid header (not Gemini?)"; | ||
221 | } | ||
222 | return NULL; /* TDOO: detailed error string */ | ||
223 | } | ||
224 | |||
225 | enum iGmStatusCode status_GmRequest(const iGmRequest *d) { | 219 | enum iGmStatusCode status_GmRequest(const iGmRequest *d) { |
226 | return d->code; | 220 | return d->code; |
227 | } | 221 | } |