diff options
-rw-r--r-- | image.c | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/image.c b/image.c index 5e7fee7..8bdce53 100644 --- a/image.c +++ b/image.c @@ -214,11 +214,11 @@ static void worker(void) { if (error) err(EX_OSERR, "pledge"); #endif - for (;;) { + for ( struct kreq req; - error = khttp_fcgi_parse(fcgi, &req); - if (error) errkcgi(EX_DATAERR, error, "khttp_fcgi_parse"); - + !(error = khttp_fcgi_parse(fcgi, &req)); + khttp_free(&req) + ) { uint32_t tileX = TileInitX; uint32_t tileY = TileInitY; if (req.fieldmap[KeyX]) { @@ -231,18 +231,18 @@ static void worker(void) { error = khttp_head( &req, kresps[KRESP_STATUS], "%s", khttps[KHTTP_200] ); - if (error == KCGI_HUP) goto next; + if (error == KCGI_HUP) continue; if (error) errkcgi(EX_IOERR, error, "khttp_head"); error = khttp_head( &req, kresps[KRESP_CONTENT_TYPE], "%s", kmimetypes[KMIME_IMAGE_PNG] ); - if (error == KCGI_HUP) goto next; + if (error == KCGI_HUP) continue; if (error) errkcgi(EX_IOERR, error, "khttp_head"); // XXX: kcgi never enables compression for FastCGI. error = khttp_body(&req); - if (error == KCGI_HUP) goto next; + if (error == KCGI_HUP) continue; if (error) errkcgi(EX_IOERR, error, "khttp_body"); struct Stream cookie = { .req = &req }; @@ -251,10 +251,9 @@ static void worker(void) { render(stream, tileX, tileY); fclose(stream); - -next: - khttp_free(&req); } + if (error != KCGI_EXIT) errkcgi(EX_PROTOCOL, error, "khttp_fcgi_parse"); + khttp_fcgi_free(fcgi); } #endif /* HAVE_KCGI */ @@ -297,7 +296,10 @@ int main(int argc, char *argv[]) { #endif #ifdef HAVE_KCGI - if (kcgi) worker(); + if (kcgi) { + worker(); + return EX_OK; + } #endif render(stdout, tileX, tileY); |