http_connection.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /* Licensed to the Apache Software Foundation (ASF) under one or more
  2. * contributor license agreements. See the NOTICE file distributed with
  3. * this work for additional information regarding copyright ownership.
  4. * The ASF licenses this file to You under the Apache License, Version 2.0
  5. * (the "License"); you may not use this file except in compliance with
  6. * the License. You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /**
  17. * @file http_connection.h
  18. * @brief Apache connection library
  19. *
  20. * @defgroup APACHE_CORE_CONNECTION Connection Library
  21. * @ingroup APACHE_CORE
  22. * @{
  23. */
  24. #ifndef APACHE_HTTP_CONNECTION_H
  25. #define APACHE_HTTP_CONNECTION_H
  26. #include "apr_network_io.h"
  27. #include "apr_buckets.h"
  28. #ifdef __cplusplus
  29. extern "C" {
  30. #endif
  31. /**
  32. * This is the protocol module driver. This calls all of the
  33. * pre-connection and connection hooks for all protocol modules.
  34. * @param c The connection on which the request is read
  35. * @param csd The mechanism on which this connection is to be read.
  36. * Most times this will be a socket, but it is up to the module
  37. * that accepts the request to determine the exact type.
  38. */
  39. AP_CORE_DECLARE(void) ap_process_connection(conn_rec *c, void *csd);
  40. /**
  41. * Shutdown the connection for writing.
  42. * @param c The connection to shutdown
  43. * @param flush Whether or not to flush pending data before
  44. * @return APR_SUCCESS or the underlying error
  45. */
  46. AP_CORE_DECLARE(apr_status_t) ap_shutdown_conn(conn_rec *c, int flush);
  47. /**
  48. * Flushes all remain data in the client send buffer
  49. * @param c The connection to flush
  50. * @remark calls ap_shutdown_conn(c, 1)
  51. */
  52. AP_CORE_DECLARE(void) ap_flush_conn(conn_rec *c);
  53. /**
  54. * This function is responsible for the following cases:
  55. * <pre>
  56. * we now proceed to read from the client until we get EOF, or until
  57. * MAX_SECS_TO_LINGER has passed. The reasons for doing this are
  58. * documented in a draft:
  59. *
  60. * http://tools.ietf.org/html/draft-ietf-http-connection-00.txt
  61. *
  62. * in a nutshell -- if we don't make this effort we risk causing
  63. * TCP RST packets to be sent which can tear down a connection before
  64. * all the response data has been sent to the client.
  65. * </pre>
  66. * @param c The connection we are closing
  67. */
  68. AP_DECLARE(void) ap_lingering_close(conn_rec *c);
  69. AP_DECLARE(int) ap_prep_lingering_close(conn_rec *c);
  70. AP_DECLARE(int) ap_start_lingering_close(conn_rec *c);
  71. /* Hooks */
  72. /**
  73. * create_connection is a RUN_FIRST hook which allows modules to create
  74. * connections. In general, you should not install filters with the
  75. * create_connection hook. If you require vhost configuration information
  76. * to make filter installation decisions, you must use the pre_connection
  77. * or install_network_transport hook. This hook should close the connection
  78. * if it encounters a fatal error condition.
  79. *
  80. * @param p The pool from which to allocate the connection record
  81. * @param server The server record to create the connection too.
  82. * @param csd The socket that has been accepted
  83. * @param conn_id A unique identifier for this connection. The ID only
  84. * needs to be unique at that time, not forever.
  85. * @param sbh A handle to scoreboard information for this connection.
  86. * @param alloc The bucket allocator to use for all bucket/brigade creations
  87. * @return An allocated connection record or NULL.
  88. */
  89. AP_DECLARE_HOOK(conn_rec *, create_connection,
  90. (apr_pool_t *p, server_rec *server, apr_socket_t *csd,
  91. long conn_id, void *sbh, apr_bucket_alloc_t *alloc))
  92. /**
  93. * This hook gives protocol modules an opportunity to set everything up
  94. * before calling the protocol handler. All pre-connection hooks are
  95. * run until one returns something other than ok or decline
  96. * @param c The connection on which the request has been received.
  97. * @param csd The mechanism on which this connection is to be read.
  98. * Most times this will be a socket, but it is up to the module
  99. * that accepts the request to determine the exact type.
  100. * @return OK or DECLINED
  101. */
  102. AP_DECLARE_HOOK(int,pre_connection,(conn_rec *c, void *csd))
  103. /**
  104. * This hook implements different protocols. After a connection has been
  105. * established, the protocol module must read and serve the request. This
  106. * function does that for each protocol module. The first protocol module
  107. * to handle the request is the last module run.
  108. * @param c The connection on which the request has been received.
  109. * @return OK or DECLINED
  110. */
  111. AP_DECLARE_HOOK(int,process_connection,(conn_rec *c))
  112. /**
  113. * This hook implements different protocols. Before a connection is closed,
  114. * protocols might have to perform some housekeeping actions, such as
  115. * sending one last goodbye packet. The connection is, unless some other
  116. * error already happened before, still open and operational.
  117. * All pre-close-connection hooks are run until one returns something
  118. * other than ok or decline
  119. * @param c The connection on which the request has been received.
  120. * @return OK or DECLINED
  121. */
  122. AP_DECLARE_HOOK(int,pre_close_connection,(conn_rec *c))
  123. /** End Of Connection (EOC) bucket */
  124. AP_DECLARE_DATA extern const apr_bucket_type_t ap_bucket_type_eoc;
  125. /**
  126. * Determine if a bucket is an End Of Connection (EOC) bucket
  127. * @param e The bucket to inspect
  128. * @return true or false
  129. */
  130. #define AP_BUCKET_IS_EOC(e) (e->type == &ap_bucket_type_eoc)
  131. /**
  132. * Make the bucket passed in an End Of Connection (EOC) bucket
  133. * @param b The bucket to make into an EOC bucket
  134. * @return The new bucket, or NULL if allocation failed
  135. */
  136. AP_DECLARE(apr_bucket *) ap_bucket_eoc_make(apr_bucket *b);
  137. /**
  138. * Create a bucket referring to an End Of Connection (EOC). This indicates
  139. * that the connection will be closed.
  140. * @param list The freelist from which this bucket should be allocated
  141. * @return The new bucket, or NULL if allocation failed
  142. */
  143. AP_DECLARE(apr_bucket *) ap_bucket_eoc_create(apr_bucket_alloc_t *list);
  144. #ifdef __cplusplus
  145. }
  146. #endif
  147. #endif /* !APACHE_HTTP_CONNECTION_H */
  148. /** @} */