Applications turn on this flag if they want to avoid any sendfile bogosity, which can be triggered based on hardware or software or configuration.
AFAIK, Solaris and z/OS are the only platforms that have no sendfile concerns which the current APR code doesn't already handle, so for non-{Solaris, z/OS}, sendfile will always return APR_ENOTIMPL when the APR_SENDFILE_AUTODETECT flag is specified. Enterprising platform gurus can decide whether or not it is practical to address all of the platform nuances with sendfile, and if appropriate modify their platform's sendfile interface. Example use: Apache 2.x uses the directive "EnableSendfile Autodetect" to turn on this APR_SENDFILE_AUTODETECT flag. The setting for EnableSendfile in the default configuration file is Autodetect. Apache will check for the ENOTIMPL return code and handle as appropriate. Alternate strategy: APR internally implements the sendfile interface using other mechanisms, such that applications don't need to check for APR_ENOTIMPL.
Index: include/apr_network_io.h =================================================================== --- include/apr_network_io.h (revision 156271) +++ include/apr_network_io.h (working copy) @@ -254,6 +254,14 @@ * @remark Optional flag passed into apr_socket_sendfile() */ #define APR_SENDFILE_DISCONNECT_SOCKET 1 +/** + * Return APR_ENOTIMPL if there is some chance that sendfile can + * misbehave. Without this flag, APR will actually call the native + * function, and there may be platform or configurat-specific issues + * which can prevent it from working properly. + * @remark Optional flag passed into apr_socket_sendfile() + */ +#define APR_SENDFILE_AUTODETECT 2 #endif /** A structure to encapsulate headers and trailers for apr_socket_sendfile */ Index: network_io/win32/sendrecv.c =================================================================== --- network_io/win32/sendrecv.c (revision 156271) +++ network_io/win32/sendrecv.c (working copy) @@ -269,6 +269,12 @@ return APR_ENOTIMPL; } + if (flags & APR_SENDFILE_AUTODETECT) { + /* no logic yet to figure out when sendfile will misbehave + */ + return APR_ENOTIMPL; + } + /* Use len to keep track of number of total bytes sent (including headers) */ bytes_to_send = *len; *len = 0; Index: network_io/unix/sendrecv.c =================================================================== --- network_io/unix/sendrecv.c (revision 156271) +++ network_io/unix/sendrecv.c (working copy) @@ -270,7 +270,12 @@ hdtr = &no_hdtr; } - /* Ignore flags for now. */ + if (flags & APR_SENDFILE_AUTODETECT) { + /* no logic yet to figure out when sendfile will misbehave + */ + return APR_ENOTIMPL; + } + flags = 0; if (hdtr->numheaders > 0) { @@ -400,7 +405,12 @@ struct sf_hdtr headerstruct; apr_size_t bytes_to_send = *len; - /* Ignore flags for now. */ + if (flags & APR_SENDFILE_AUTODETECT) { + /* no logic yet to figure out when sendfile will misbehave + */ + return APR_ENOTIMPL; + } + flags = 0; if (!hdtr) { @@ -556,7 +566,11 @@ hdtr = &no_hdtr; } - /* Ignore flags for now. */ + if (flags & APR_SENDFILE_AUTODETECT) { + /* no logic yet to figure out when sendfile will misbehave + */ + return APR_ENOTIMPL; + } flags = 0; /* HP-UX can only send one header iovec and one footer iovec; try to @@ -685,7 +699,13 @@ hdtr = &no_hdtr; } - /* Ignore flags for now. */ +#ifdef _AIX + if (flags & APR_SENDFILE_AUTODETECT) { + /* no logic yet to figure out when sendfile will misbehave + */ + return APR_ENOTIMPL; + } +#endif flags = 0; /* word to the wise: by default, AIX stores files sent by send_file()