00001 /* 00002 * Copyright 2008-2010 Arsen Chaloyan 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 * 00016 * $Id: apt_pollset.h 1565 2010-03-06 07:13:04Z achaloyan $ 00017 */ 00018 00019 #ifndef APT_POLLSET_H 00020 #define APT_POLLSET_H 00021 00022 /** 00023 * @file apt_pollset.h 00024 * @brief Interruptable APR-Pollset 00025 */ 00026 00027 /** 00028 * Wakeup builtin API of the pollset is introduced only in APR-1.4 00029 * and it is not available for APR-1.2 and APR-1.3 versions. Thus 00030 * apt_pollset_t is an extension of apr_pollset_t and provides 00031 * pollset wakeup capabilities the similar way as it's implemented 00032 * in APR-1.4 trunk 00033 */ 00034 00035 #include <apr_poll.h> 00036 #include "apt.h" 00037 00038 APT_BEGIN_EXTERN_C 00039 00040 /** Opaque pollset declaration */ 00041 typedef struct apt_pollset_t apt_pollset_t; 00042 00043 /** 00044 * Create interruptable pollset on top of APR pollset. 00045 * @param size the maximum number of descriptors pollset can hold 00046 * @param pool the pool to allocate memory from 00047 */ 00048 APT_DECLARE(apt_pollset_t*) apt_pollset_create(apr_uint32_t size, apr_pool_t *pool); 00049 00050 /** 00051 * Destroy pollset. 00052 * @param pollset the pollset to destroy 00053 */ 00054 APT_DECLARE(apt_bool_t) apt_pollset_destroy(apt_pollset_t *pollset); 00055 00056 /** 00057 * Add pollset descriptor to a pollset. 00058 * @param pollset the pollset to add the descriptor to 00059 * @param descriptor the descriptor to add 00060 */ 00061 APT_DECLARE(apt_bool_t) apt_pollset_add(apt_pollset_t *pollset, const apr_pollfd_t *descriptor); 00062 00063 /** 00064 * Remove pollset descriptor from a pollset. 00065 * @param pollset the pollset to remove the descriptor from 00066 * @param descriptor the descriptor to remove 00067 */ 00068 APT_DECLARE(apt_bool_t) apt_pollset_remove(apt_pollset_t *pollset, const apr_pollfd_t *descriptor); 00069 00070 /** 00071 * Block for activity on the descriptor(s) in a pollset. 00072 * @param pollset the pollset to use 00073 * @param timeout the timeout in microseconds 00074 * @param num the number of signalled descriptors (output parameter) 00075 * @param descriptors the array of signalled descriptors (output parameter) 00076 */ 00077 APT_DECLARE(apr_status_t) apt_pollset_poll( 00078 apt_pollset_t *pollset, 00079 apr_interval_time_t timeout, 00080 apr_int32_t *num, 00081 const apr_pollfd_t **descriptors); 00082 00083 /** 00084 * Interrupt the blocked poll call. 00085 * @param pollset the pollset to use 00086 */ 00087 APT_DECLARE(apt_bool_t) apt_pollset_wakeup(apt_pollset_t *pollset); 00088 00089 /** 00090 * Match against builtin wake up descriptor in a pollset. 00091 * @param pollset the pollset to use 00092 * @param descriptor the descriptor to match 00093 */ 00094 APT_DECLARE(apt_bool_t) apt_pollset_is_wakeup(apt_pollset_t *pollset, const apr_pollfd_t *descriptor); 00095 00096 APT_END_EXTERN_C 00097 00098 #endif /* APT_POLLSET_H */