00001 /* Copyright 2000-2004 The Apache Software Foundation 00002 * 00003 * Licensed under the Apache License, Version 2.0 (the "License"); 00004 * you may not use this file except in compliance with the License. 00005 * You may obtain a copy of the License at 00006 * 00007 * http://www.apache.org/licenses/LICENSE-2.0 00008 * 00009 * Unless required by applicable law or agreed to in writing, software 00010 * distributed under the License is distributed on an "AS IS" BASIS, 00011 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00012 * See the License for the specific language governing permissions and 00013 * limitations under the License. 00014 */ 00015 00016 #ifndef APR_POLL_H 00017 #define APR_POLL_H 00018 /** 00019 * @file apr_poll.h 00020 * @brief APR Poll interface 00021 */ 00022 #include "apr.h" 00023 #include "apr_pools.h" 00024 #include "apr_errno.h" 00025 #include "apr_inherit.h" 00026 #include "apr_file_io.h" 00027 #include "apr_network_io.h" 00028 00029 #if APR_HAVE_NETINET_IN_H 00030 #include <netinet/in.h> 00031 #endif 00032 00033 #ifdef __cplusplus 00034 extern "C" { 00035 #endif /* __cplusplus */ 00036 00037 /** 00038 * @defgroup apr_poll Poll Routines 00039 * @ingroup APR 00040 * @{ 00041 */ 00042 00043 /** 00044 * Poll options 00045 */ 00046 #define APR_POLLIN 0x001 /**< Can read without blocking */ 00047 #define APR_POLLPRI 0x002 /**< Priority data available */ 00048 #define APR_POLLOUT 0x004 /**< Can write without blocking */ 00049 #define APR_POLLERR 0x010 /**< Pending error */ 00050 #define APR_POLLHUP 0x020 /**< Hangup occurred */ 00051 #define APR_POLLNVAL 0x040 /**< Descriptior invalid */ 00052 00053 /** Used in apr_pollfd_t to determine what the apr_descriptor is */ 00054 typedef enum { 00055 APR_NO_DESC, /**< nothing here */ 00056 APR_POLL_SOCKET, /**< descriptor refers to a socket */ 00057 APR_POLL_FILE, /**< descriptor refers to a file */ 00058 APR_POLL_LASTDESC /**< descriptor is the last one in the list */ 00059 } apr_datatype_e ; 00060 00061 /** Union of either an APR file or socket. */ 00062 typedef union { 00063 apr_file_t *f; /**< file */ 00064 apr_socket_t *s; /**< socket */ 00065 } apr_descriptor; 00066 00067 /** @see apr_pollfd_t */ 00068 typedef struct apr_pollfd_t apr_pollfd_t; 00069 00070 /** Poll descriptor set. */ 00071 struct apr_pollfd_t { 00072 apr_pool_t *p; /**< associated pool */ 00073 apr_datatype_e desc_type; /**< descriptor type */ 00074 apr_int16_t reqevents; /**< requested events */ 00075 apr_int16_t rtnevents; /**< returned events */ 00076 apr_descriptor desc; /**< @see apr_descriptor */ 00077 void *client_data; /**< allows app to associate context */ 00078 }; 00079 00080 00081 /* General-purpose poll API for arbitrarily large numbers of 00082 * file descriptors 00083 */ 00084 00085 /** Opaque structure used for pollset API */ 00086 typedef struct apr_pollset_t apr_pollset_t; 00087 00088 /** 00089 * Setup a pollset object 00090 * @param pollset The pointer in which to return the newly created object 00091 * @param size The maximum number of descriptors that this pollset can hold 00092 * @param p The pool from which to allocate the pollset 00093 * @param flags Optional flags to modify the operation of the pollset 00094 * (reserved for future expansion) 00095 */ 00096 APR_DECLARE(apr_status_t) apr_pollset_create(apr_pollset_t **pollset, 00097 apr_uint32_t size, 00098 apr_pool_t *p, 00099 apr_uint32_t flags); 00100 00101 /** 00102 * Destroy a pollset object 00103 * @param pollset The pollset to destroy 00104 */ 00105 APR_DECLARE(apr_status_t) apr_pollset_destroy(apr_pollset_t *pollset); 00106 00107 /** 00108 * Add a socket or file descriptor to a pollset 00109 * @param pollset The pollset to which to add the descriptor 00110 * @param descriptor The descriptor to add 00111 * @remark If you set client_data in the descriptor, that value 00112 * will be returned in the client_data field whenever this 00113 * descriptor is signalled in apr_pollset_poll(). 00114 */ 00115 APR_DECLARE(apr_status_t) apr_pollset_add(apr_pollset_t *pollset, 00116 const apr_pollfd_t *descriptor); 00117 00118 /** 00119 * Remove a descriptor from a pollset 00120 * @param pollset The pollset from which to remove the descriptor 00121 * @param descriptor The descriptor to remove 00122 */ 00123 APR_DECLARE(apr_status_t) apr_pollset_remove(apr_pollset_t *pollset, 00124 const apr_pollfd_t *descriptor); 00125 00126 /** 00127 * Block for activity on the descriptor(s) in a pollset 00128 * @param pollset The pollset to use 00129 * @param timeout Timeout in microseconds 00130 * @param num Number of signalled descriptors (output parameter) 00131 * @param descriptors Array of signalled descriptors (output parameter) 00132 */ 00133 APR_DECLARE(apr_status_t) apr_pollset_poll(apr_pollset_t *pollset, 00134 apr_interval_time_t timeout, 00135 apr_int32_t *num, 00136 const apr_pollfd_t **descriptors); 00137 00138 00139 /** 00140 * Poll the sockets in the poll structure 00141 * @param aprset The poll structure we will be using. 00142 * @param numsock The number of sockets we are polling 00143 * @param nsds The number of sockets signalled. 00144 * @param timeout The amount of time in microseconds to wait. This is 00145 * a maximum, not a minimum. If a socket is signalled, we 00146 * will wake up before this time. A negative number means 00147 * wait until a socket is signalled. 00148 * @remark The number of sockets signalled is returned in the third argument. 00149 * This is a blocking call, and it will not return until either a 00150 * socket has been signalled, or the timeout has expired. 00151 */ 00152 APR_DECLARE(apr_status_t) apr_poll(apr_pollfd_t *aprset, apr_int32_t numsock, 00153 apr_int32_t *nsds, 00154 apr_interval_time_t timeout); 00155 00156 /** @} */ 00157 00158 00159 #ifdef __cplusplus 00160 } 00161 #endif 00162 00163 #endif /* ! APR_POLL_H */ 00164