/* Licensed to the Apache Software Foundation (ASF) under one or more *contributorlicenseagreements.SeetheNOTICEfiledistributedwith *thisworkforadditionalinformationregardingcopyrightownership. *TheASFlicensesthisfiletoYouundertheApacheLicense,Version2.0 *(the"License");youmaynotusethisfileexceptincompliancewith *theLicense.YoumayobtainacopyoftheLicenseat * *http://www.apache.org/licenses/LICENSE-2.0 * *Unlessrequiredbyapplicablelaworagreedtoinwriting,software *distributedundertheLicenseisdistributedonan"ASIS"BASIS, *WITHOUTWARRANTIESORCONDITIONSOFANYKIND,eitherexpressorimplied. *SeetheLicenseforthespecificlanguagegoverningpermissionsand *limitationsundertheLicense.
*/
AP_DECLARE(int) ap_prep_lingering_close(conn_rec *c)
{ /* Give protocol handlers one last chance to raise their voice */
ap_run_pre_close_connection(c);
if (c->sbh) {
ap_update_child_status(c->sbh, SERVER_CLOSING, NULL);
} return0;
}
/* we now proceed to read from the client until we get EOF, or until *MAX_SECS_TO_LINGERhaspassed.Thereasonsfordoingthisare *documentedinadraft: * *http://tools.ietf.org/html/draft-ietf-http-connection-00.txt * *inanutshell--ifwedon'tmakethiseffortweriskcausing *TCPRSTpacketstobesentwhichcanteardownaconnectionbefore *alltheresponsedatahasbeensenttotheclient.
*/ #define SECONDS_TO_LINGER 2
/* Close the connection, being careful to send out whatever is still *inourbuffers.Ifpossible,trytoavoidahardcloseuntilthe *clienthasACKedourFINand/orhasstoppedsendingusdata.
*/
/* Send any leftover data to the client, but never try to again */
ap_flush_conn(c);
#ifdef NO_LINGCLOSE return1; #else /* Shut down the socket for write, which will send a FIN *tothepeer.
*/ return (c->aborted || apr_socket_shutdown(csd, APR_SHUTDOWN_WRITE)); #endif
}
if (!csd) { /* Be safe with third-party modules that: *ap_set_core_module_config(c->conn_config,NULL) *tono-opap_lingering_close().
*/
c->aborted = 1; return;
}
if (ap_start_lingering_close(c)) {
apr_socket_close(csd); return;
}
/* Read available data from the client whilst it continues sending *it,foramaximumtimeofMAX_SECS_TO_LINGER.Iftheclient *doesnotsendanydatawithin2seconds(avaluepulledfrom *Apache1.3whichseemstoworkwell),giveup.
*/
apr_socket_timeout_set(csd, apr_time_from_sec(SECONDS_TO_LINGER));
apr_socket_opt_set(csd, APR_INCOMPLETE_READ, 1);
/* The common path here is that the initial apr_socket_recv() call *willreturn0bytesread;sothatcasemustavoidtheexpensive
* apr_time_now() call and time arithmetic. */
do {
nbytes = sizeof(dummybuf); if (apr_socket_recv(csd, dummybuf, &nbytes) || nbytes == 0) break;
now = apr_time_now(); if (timeup == 0) { /* *Firsttimethrough; *calculatenow+30seconds(MAX_SECS_TO_LINGER). * *Ifsomemodulerequestedashortenedwaitingperiod,onlywaitfor *2s(SECONDS_TO_LINGER).Thisisusefulformitigatingcertain *DoSattacks.
*/ if (apr_table_get(c->notes, "short-lingering-close")) {
timeup = now + apr_time_from_sec(SECONDS_TO_LINGER);
} else {
timeup = now + apr_time_from_sec(MAX_SECS_TO_LINGER);
} continue;
}
} while (now < timeup);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.