Skip to content

Commit e16e67a

Browse files
committed
Fixed logic & applied styling standard
* Now that we are allowing `short reads`, we need to not re-zero `resp` in the loop * We need to cast `&resp` for the `recv` call in order to advance the memory address as expected * We should handle `EINTR` `errno`s * We need to break if an unexpected response type/etc. is received * In order to later prevent following the `if (ret <=0)` path
1 parent 1d66fd5 commit e16e67a

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

src/mod_tile.c

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -389,21 +389,27 @@ static int request_tile(request_rec *r, struct protocol *cmd, int renderImmediat
389389
s = poll(&rx, 1, timeout * 1000);
390390

391391
if (s > 0) {
392-
bzero(&resp, sizeof(struct protocol));
393-
ret = recv(fd, &resp + already_read, want - already_read, 0);
392+
ret = recv(fd, (char *)&resp + already_read, want - already_read, 0);
394393

395-
// a return value of <= 0 means that there is some kind of error
394+
// a return value of <= 0 means that there is some kind of error or EOF
396395
if (ret <= 0) {
396+
// handle interrupted system calls gracefully
397+
if (ret == -1 && errno == EINTR) {
398+
continue;
399+
}
400+
397401
ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, r, "request_tile: Failed to read response from rendering socket: %s",
398-
strerror(errno));
402+
strerror(errno));
399403
break;
400404
}
401405

402406
// other return values mean that some bytes were read, not necessary as many as we wanted
403407
already_read += ret;
408+
404409
// first integer in message is protocol version
405-
if (already_read >= sizeof(int))
410+
if (already_read >= sizeof(int)) {
406411
want = (resp.ver == 3) ? sizeof(struct protocol) : sizeof(struct protocol_v2);
412+
}
407413

408414
// do we have a complete packet?
409415
if (already_read == want) {
@@ -417,21 +423,22 @@ static int request_tile(request_rec *r, struct protocol *cmd, int renderImmediat
417423
}
418424
} else {
419425
ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, r,
420-
"Response does not match request: xml(%s,%s) z(%d,%d) x(%d,%d) y(%d,%d)", cmd->xmlname,
421-
resp.xmlname, cmd->z, resp.z, cmd->x, resp.x, cmd->y, resp.y);
426+
"Response does not match request: xml(%s,%s) z(%d,%d) x(%d,%d) y(%d,%d)", cmd->xmlname,
427+
resp.xmlname, cmd->z, resp.z, cmd->x, resp.x, cmd->y, resp.y);
428+
break;
422429
}
423430
}
424431
} else if (s == 0) {
425432
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r,
426-
"request_tile: Request xml(%s) z(%d) x(%d) y(%d) could not be rendered in %i seconds",
427-
cmd->xmlname, cmd->z, cmd->x, cmd->y,
428-
timeout);
433+
"request_tile: Request xml(%s) z(%d) x(%d) y(%d) could not be rendered in %i seconds",
434+
cmd->xmlname, cmd->z, cmd->x, cmd->y,
435+
timeout);
429436
break;
430437
} else {
431438
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r,
432-
"request_tile: Request xml(%s) z(%d) x(%d) y(%d) timeout %i seconds failed with reason: %s",
433-
cmd->xmlname, cmd->z, cmd->x, cmd->y,
434-
timeout, strerror(errno));
439+
"request_tile: Request xml(%s) z(%d) x(%d) y(%d) timeout %i seconds failed with reason: %s",
440+
cmd->xmlname, cmd->z, cmd->x, cmd->y,
441+
timeout, strerror(errno));
435442
break;
436443
}
437444
}

0 commit comments

Comments
 (0)