Skip to content

Commit

Permalink
gopher: check remaining time left during write busy loop
Browse files Browse the repository at this point in the history
Assisted-by: Jay Satiro
Reviewed-by: Daniel Stenberg

Closes curl#5214
  • Loading branch information
mback2k committed Apr 11, 2020
1 parent dd0365d commit 3c63de3
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions lib/gopher.c
Expand Up @@ -28,6 +28,7 @@
#include <curl/curl.h>
#include "transfer.h"
#include "sendf.h"
#include "connect.h"
#include "progress.h"
#include "gopher.h"
#include "select.h"
Expand Down Expand Up @@ -83,8 +84,10 @@ static CURLcode gopher_do(struct connectdata *conn, bool *done)
char *query = data->state.up.query;
char *sel = NULL;
char *sel_org = NULL;
timediff_t timeleft;
ssize_t amount, k;
size_t len;
int what;

*done = TRUE; /* unconditionally */

Expand Down Expand Up @@ -139,19 +142,29 @@ static CURLcode gopher_do(struct connectdata *conn, bool *done)
else
break;

timeleft = Curl_timeleft(conn->data, NULL, FALSE);
if(timeleft < 0) {
result = CURLE_OPERATION_TIMEDOUT;
break;
}
if(!timeleft || timeleft > TIME_T_MAX)
timeleft = TIME_T_MAX;

/* Don't busyloop. The entire loop thing is a work-around as it causes a
BLOCKING behavior which is a NO-NO. This function should rather be
split up in a do and a doing piece where the pieces that aren't
possible to send now will be sent in the doing function repeatedly
until the entire request is sent.
Wait a while for the socket to be writable. Note that this doesn't
acknowledge the timeout.
*/
if(SOCKET_WRITABLE(sockfd, 100) < 0) {
what = SOCKET_WRITABLE(sockfd, timeleft) < 0;
if(what < 0) {
result = CURLE_SEND_ERROR;
break;
}
else if(!what) {
result = CURLE_OPERATION_TIMEDOUT;
break;
}
}

free(sel_org);
Expand Down

0 comments on commit 3c63de3

Please sign in to comment.