Skip to content

Commit c3d689a

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 unsepected response type/etc. is received) * In order to later prevent following the `if (ret <=0)` path
1 parent 94565b5 commit c3d689a

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
@@ -307,21 +307,27 @@ static int request_tile(request_rec *r, struct protocol *cmd, int renderImmediat
307307
s = poll(&rx, 1, timeout * 1000);
308308

309309
if (s > 0) {
310-
bzero(&resp, sizeof(struct protocol));
311-
ret = recv(fd, &resp + already_read, want - already_read, 0);
310+
ret = recv(fd, (char *)&resp + already_read, want - already_read, 0);
312311

313-
// a return value of <= 0 means that there is some kind of error
312+
// a return value of <= 0 means that there is some kind of error or EOF
314313
if (ret <= 0) {
314+
// handle interrupted system calls gracefully
315+
if (ret == -1 && errno == EINTR) {
316+
continue;
317+
}
318+
315319
ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, r, "request_tile: Failed to read response from rendering socket: %s",
316-
strerror(errno));
320+
strerror(errno));
317321
break;
318322
}
319323

320324
// other return values mean that some bytes were read, not necessary as many as we wanted
321325
already_read += ret;
326+
322327
// first integer in message is protocol version
323-
if (already_read >= sizeof(int))
328+
if (already_read >= sizeof(int)) {
324329
want = (resp.ver == 3) ? sizeof(struct protocol) : sizeof(struct protocol_v2);
330+
}
325331

326332
// do we have a complete packet?
327333
if (already_read == want) {
@@ -335,21 +341,22 @@ static int request_tile(request_rec *r, struct protocol *cmd, int renderImmediat
335341
}
336342
} else {
337343
ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, r,
338-
"Response does not match request: xml(%s,%s) z(%d,%d) x(%d,%d) y(%d,%d)", cmd->xmlname,
339-
resp.xmlname, cmd->z, resp.z, cmd->x, resp.x, cmd->y, resp.y);
344+
"Response does not match request: xml(%s,%s) z(%d,%d) x(%d,%d) y(%d,%d)", cmd->xmlname,
345+
resp.xmlname, cmd->z, resp.z, cmd->x, resp.x, cmd->y, resp.y);
346+
break;
340347
}
341348
}
342349
} else if (s == 0) {
343350
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r,
344-
"request_tile: Request xml(%s) z(%d) x(%d) y(%d) could not be rendered in %i seconds",
345-
cmd->xmlname, cmd->z, cmd->x, cmd->y,
346-
timeout);
351+
"request_tile: Request xml(%s) z(%d) x(%d) y(%d) could not be rendered in %i seconds",
352+
cmd->xmlname, cmd->z, cmd->x, cmd->y,
353+
timeout);
347354
break;
348355
} else {
349356
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r,
350-
"request_tile: Request xml(%s) z(%d) x(%d) y(%d) timeout %i seconds failed with reason: %s",
351-
cmd->xmlname, cmd->z, cmd->x, cmd->y,
352-
timeout, strerror(errno));
357+
"request_tile: Request xml(%s) z(%d) x(%d) y(%d) timeout %i seconds failed with reason: %s",
358+
cmd->xmlname, cmd->z, cmd->x, cmd->y,
359+
timeout, strerror(errno));
353360
break;
354361
}
355362
}

0 commit comments

Comments
 (0)