[core] consolidate duplicated read-to-close code
[core] consolidate duplicated read-to-close code

more efficiently detect end-of-stream when closing connection

log fd prior to resetting fd to -1 when log_state_handling enabled

PatchyFog/lighttpd1.4-mbedtls,gstrauss/lighttpd1.4,PatchyFog/lighttpd1.4-mbedtls,gstrauss/lighttpd1.4,lighttpd/lighttpd1.4,lighttpd/lighttpd1.4,PatchyFog/lighttpd1.4-mbedtls,lighttpd/lighttpd1.4,lighttpd/lighttpd1.4,gstrauss/lighttpd1.4,PatchyFog/lighttpd1.4-mbedtls,gstrauss/lighttpd1.4,PatchyFog/lighttpd1.4-mbedtls,gstrauss/lighttpd1.4,PatchyFog/lighttpd1.4-mbedtls,gstrauss/lighttpd1.4,PatchyFog/lighttpd1.4-mbedtls,lighttpd/lighttpd1.4,lighttpd/lighttpd1.4