summaryrefslogtreecommitdiff
path: root/src/gmrequest.c
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2020-11-07 13:39:36 +0200
committerJaakko Keränen <jaakko.keranen@iki.fi>2020-11-07 13:39:36 +0200
commitd11b904438cb954f783245cfb4f1f06e5b2d8993 (patch)
tree75b785d119af6099f21bf27a121d385886a00357 /src/gmrequest.c
parent64b9848f878ccd75aae75bf4d8d3f8a364f28ddc (diff)
GmRequest: Removed timeouts
No automatic timeouts to facilitate long connections. The server can indicate closing of the connection via TLS or by closing the socket.
Diffstat (limited to 'src/gmrequest.c')
-rw-r--r--src/gmrequest.c32
1 files changed, 18 insertions, 14 deletions
diff --git a/src/gmrequest.c b/src/gmrequest.c
index a83a7666..bad45604 100644
--- a/src/gmrequest.c
+++ b/src/gmrequest.c
@@ -105,7 +105,7 @@ void deserialize_GmResponse(iGmResponse *d, iStream *ins) {
105 105
106/*----------------------------------------------------------------------------------------------*/ 106/*----------------------------------------------------------------------------------------------*/
107 107
108static const int bodyTimeout_GmRequest_ = 3000; /* ms */ 108//static const int bodyTimeout_GmRequest_ = 3000; /* ms */
109 109
110enum iGmRequestState { 110enum iGmRequestState {
111 initialized_GmRequestState, 111 initialized_GmRequestState,
@@ -123,15 +123,15 @@ struct Impl_GmRequest {
123 iString url; 123 iString url;
124 iTlsRequest * req; 124 iTlsRequest * req;
125 iGmResponse resp; 125 iGmResponse resp;
126 uint32_t timeoutId; /* in case server doesn't close the connection */ 126 //uint32_t timeoutId; /* in case server doesn't close the connection */
127 iAudience * updated; 127 iAudience * updated;
128 iAudience * timeout; 128// iAudience * timeout;
129 iAudience * finished; 129 iAudience * finished;
130}; 130};
131 131
132iDefineObjectConstructionArgs(GmRequest, (iGmCerts *certs), certs) 132iDefineObjectConstructionArgs(GmRequest, (iGmCerts *certs), certs)
133iDefineAudienceGetter(GmRequest, updated) 133iDefineAudienceGetter(GmRequest, updated)
134iDefineAudienceGetter(GmRequest, timeout) 134//iDefineAudienceGetter(GmRequest, timeout)
135iDefineAudienceGetter(GmRequest, finished) 135iDefineAudienceGetter(GmRequest, finished)
136 136
137void init_GmRequest(iGmRequest *d, iGmCerts *certs) { 137void init_GmRequest(iGmRequest *d, iGmCerts *certs) {
@@ -139,11 +139,11 @@ void init_GmRequest(iGmRequest *d, iGmCerts *certs) {
139 init_GmResponse(&d->resp); 139 init_GmResponse(&d->resp);
140 init_String(&d->url); 140 init_String(&d->url);
141 d->certs = certs; 141 d->certs = certs;
142 d->timeoutId = 0; 142// d->timeoutId = 0;
143 d->req = NULL; 143 d->req = NULL;
144 d->state = initialized_GmRequestState; 144 d->state = initialized_GmRequestState;
145 d->updated = NULL; 145 d->updated = NULL;
146 d->timeout = NULL; 146// d->timeout = NULL;
147 d->finished = NULL; 147 d->finished = NULL;
148} 148}
149 149
@@ -153,9 +153,9 @@ void deinit_GmRequest(iGmRequest *d) {
153 iDisconnectObject(TlsRequest, d->req, finished, d); 153 iDisconnectObject(TlsRequest, d->req, finished, d);
154 } 154 }
155 lock_Mutex(&d->mutex); 155 lock_Mutex(&d->mutex);
156 if (d->timeoutId) { 156// if (d->timeoutId) {
157 SDL_RemoveTimer(d->timeoutId); 157// SDL_RemoveTimer(d->timeoutId);
158 } 158// }
159 if (!isFinished_GmRequest(d)) { 159 if (!isFinished_GmRequest(d)) {
160 unlock_Mutex(&d->mutex); 160 unlock_Mutex(&d->mutex);
161 cancel_TlsRequest(d->req); 161 cancel_TlsRequest(d->req);
@@ -166,7 +166,7 @@ void deinit_GmRequest(iGmRequest *d) {
166 } 166 }
167 iRelease(d->req); 167 iRelease(d->req);
168 d->req = NULL; 168 d->req = NULL;
169 delete_Audience(d->timeout); 169// delete_Audience(d->timeout);
170 delete_Audience(d->finished); 170 delete_Audience(d->finished);
171 delete_Audience(d->updated); 171 delete_Audience(d->updated);
172 deinit_GmResponse(&d->resp); 172 deinit_GmResponse(&d->resp);
@@ -179,6 +179,7 @@ void setUrl_GmRequest(iGmRequest *d, const iString *url) {
179 urlEncodeSpaces_String(&d->url); 179 urlEncodeSpaces_String(&d->url);
180} 180}
181 181
182#if 0
182static uint32_t timedOutWhileReceivingBody_GmRequest_(uint32_t interval, void *obj) { 183static uint32_t timedOutWhileReceivingBody_GmRequest_(uint32_t interval, void *obj) {
183 /* Note: Called from SDL's timer thread. */ 184 /* Note: Called from SDL's timer thread. */
184 iGmRequest *d = obj; 185 iGmRequest *d = obj;
@@ -187,11 +188,13 @@ static uint32_t timedOutWhileReceivingBody_GmRequest_(uint32_t interval, void *o
187 iUnused(interval); 188 iUnused(interval);
188 return 0; 189 return 0;
189} 190}
191#endif
190 192
191void cancel_GmRequest(iGmRequest *d) { 193void cancel_GmRequest(iGmRequest *d) {
192 cancel_TlsRequest(d->req); 194 cancel_TlsRequest(d->req);
193} 195}
194 196
197#if 0
195static void restartTimeout_GmRequest_(iGmRequest *d) { 198static void restartTimeout_GmRequest_(iGmRequest *d) {
196 /* Note: `d` is currently locked. */ 199 /* Note: `d` is currently locked. */
197 if (d->timeoutId) { 200 if (d->timeoutId) {
@@ -199,6 +202,7 @@ static void restartTimeout_GmRequest_(iGmRequest *d) {
199 } 202 }
200 d->timeoutId = SDL_AddTimer(bodyTimeout_GmRequest_, timedOutWhileReceivingBody_GmRequest_, d); 203 d->timeoutId = SDL_AddTimer(bodyTimeout_GmRequest_, timedOutWhileReceivingBody_GmRequest_, d);
201} 204}
205#endif
202 206
203static void checkServerCertificate_GmRequest_(iGmRequest *d) { 207static void checkServerCertificate_GmRequest_(iGmRequest *d) {
204 const iTlsCertificate *cert = serverCertificate_TlsRequest(d->req); 208 const iTlsCertificate *cert = serverCertificate_TlsRequest(d->req);
@@ -272,12 +276,12 @@ static void readIncoming_GmRequest_(iAnyObject *obj) {
272 notifyUpdate = iTrue; 276 notifyUpdate = iTrue;
273 /* Start a timeout for the remainder of the response, in case the connection 277 /* Start a timeout for the remainder of the response, in case the connection
274 remains open. */ 278 remains open. */
275 restartTimeout_GmRequest_(d); 279// restartTimeout_GmRequest_(d);
276 } 280 }
277 } 281 }
278 else if (d->state == receivingBody_GmRequestState) { 282 else if (d->state == receivingBody_GmRequestState) {
279 append_Block(&d->resp.body, data); 283 append_Block(&d->resp.body, data);
280 restartTimeout_GmRequest_(d); 284// restartTimeout_GmRequest_(d);
281 notifyUpdate = iTrue; 285 notifyUpdate = iTrue;
282 } 286 }
283 initCurrent_Time(&d->resp.when); 287 initCurrent_Time(&d->resp.when);
@@ -300,8 +304,8 @@ static void requestFinished_GmRequest_(iAnyObject *obj) {
300 delete_Block(data); 304 delete_Block(data);
301 initCurrent_Time(&d->resp.when); 305 initCurrent_Time(&d->resp.when);
302 } 306 }
303 SDL_RemoveTimer(d->timeoutId); 307// SDL_RemoveTimer(d->timeoutId);
304 d->timeoutId = 0; 308// d->timeoutId = 0;
305 d->state = (status_TlsRequest(d->req) == error_TlsRequestStatus ? failure_GmRequestState 309 d->state = (status_TlsRequest(d->req) == error_TlsRequestStatus ? failure_GmRequestState
306 : finished_GmRequestState); 310 : finished_GmRequestState);
307 if (d->state == failure_GmRequestState) { 311 if (d->state == failure_GmRequestState) {