Created
January 17, 2017 07:47
-
-
Save famzah/125a91971fba3450dd4926fe13e0ede6 to your computer and use it in GitHub Desktop.
mod_fcgi: Excessive memory usage when large files are uploaded
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define FCGID_VEC_COUNT 8 | |
apr_status_t proc_write_ipc(fcgid_ipc *ipc_handle, | |
apr_bucket_brigade *output_brigade) | |
{ | |
apr_status_t rv; | |
struct iovec vec[FCGID_VEC_COUNT]; | |
int nvec = 0; | |
apr_bucket *e; | |
for (e = APR_BRIGADE_FIRST(output_brigade); | |
e != APR_BRIGADE_SENTINEL(output_brigade); | |
e = APR_BUCKET_NEXT(e)) { | |
apr_size_t len; | |
const char* base; | |
if (APR_BUCKET_IS_METADATA(e)) { | |
continue; | |
} | |
if ((rv = apr_bucket_read(e, &base, &len, | |
APR_BLOCK_READ)) != APR_SUCCESS) { | |
ap_log_rerror(APLOG_MARK, APLOG_WARNING, rv, ipc_handle->request, | |
"mod_fcgid: can't read request from bucket"); | |
return rv; | |
} | |
vec[nvec].iov_len = len; | |
vec[nvec].iov_base = (char*) base; | |
if (nvec == (FCGID_VEC_COUNT - 1)) { | |
/* It's time to write now */ | |
if ((rv = | |
writev_it_all(ipc_handle, vec, | |
FCGID_VEC_COUNT)) != APR_SUCCESS) | |
return rv; | |
nvec = 0; | |
} | |
else | |
nvec++; | |
} | |
/* There are something left */ | |
if (nvec != 0) { | |
if ((rv = writev_it_all(ipc_handle, vec, nvec)) != APR_SUCCESS) | |
return rv; | |
} | |
return APR_SUCCESS; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment