Main Page | Modules | Data Structures | File List | Data Fields | Globals | Related Pages

apr_portable.h

Go to the documentation of this file.
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 /* This header file is where you should put ANY platform specific information. 00017 * This should be the only header file that programs need to include that 00018 * actually has platform dependant code which refers to the . 00019 */ 00020 #ifndef APR_PORTABLE_H 00021 #define APR_PORTABLE_H 00022 /** 00023 * @file apr_portable.h 00024 * @brief APR Portability Routines 00025 */ 00026 00027 #include "apr.h" 00028 #include "apr_pools.h" 00029 #include "apr_thread_proc.h" 00030 #include "apr_file_io.h" 00031 #include "apr_network_io.h" 00032 #include "apr_errno.h" 00033 #include "apr_global_mutex.h" 00034 #include "apr_proc_mutex.h" 00035 #include "apr_time.h" 00036 #include "apr_dso.h" 00037 #include "apr_shm.h" 00038 00039 #if APR_HAVE_DIRENT_H 00040 #include <dirent.h> 00041 #endif 00042 #if APR_HAVE_FCNTL_H 00043 #include <fcntl.h> 00044 #endif 00045 #if APR_HAVE_PTHREAD_H 00046 #include <pthread.h> 00047 #endif 00048 00049 #ifdef __cplusplus 00050 extern "C" { 00051 #endif /* __cplusplus */ 00052 00053 /** 00054 * @defgroup apr_portabile Portability Routines 00055 * @ingroup APR 00056 * @{ 00057 */ 00058 00059 #ifdef WIN32 00060 /* The primitives for Windows types */ 00061 typedef HANDLE apr_os_file_t; 00062 typedef HANDLE apr_os_dir_t; 00063 typedef SOCKET apr_os_sock_t; 00064 typedef HANDLE apr_os_proc_mutex_t; 00065 typedef HANDLE apr_os_thread_t; 00066 typedef HANDLE apr_os_proc_t; 00067 typedef DWORD apr_os_threadkey_t; 00068 typedef FILETIME apr_os_imp_time_t; 00069 typedef SYSTEMTIME apr_os_exp_time_t; 00070 typedef HANDLE apr_os_dso_handle_t; 00071 typedef HANDLE apr_os_shm_t; 00072 00073 #elif defined(OS2) 00074 typedef HFILE apr_os_file_t; 00075 typedef HDIR apr_os_dir_t; 00076 typedef int apr_os_sock_t; 00077 typedef HMTX apr_os_proc_mutex_t; 00078 typedef TID apr_os_thread_t; 00079 typedef PID apr_os_proc_t; 00080 typedef PULONG apr_os_threadkey_t; 00081 typedef struct timeval apr_os_imp_time_t; 00082 typedef struct tm apr_os_exp_time_t; 00083 typedef HMODULE apr_os_dso_handle_t; 00084 typedef void* apr_os_shm_t; 00085 00086 #elif defined(__BEOS__) 00087 #include <kernel/OS.h> 00088 #include <kernel/image.h> 00089 00090 struct apr_os_proc_mutex_t { 00091 sem_id sem; 00092 int32 ben; 00093 }; 00094 00095 typedef int apr_os_file_t; 00096 typedef DIR apr_os_dir_t; 00097 typedef int apr_os_sock_t; 00098 typedef struct apr_os_proc_mutex_t apr_os_proc_mutex_t; 00099 typedef thread_id apr_os_thread_t; 00100 typedef thread_id apr_os_proc_t; 00101 typedef int apr_os_threadkey_t; 00102 typedef struct timeval apr_os_imp_time_t; 00103 typedef struct tm apr_os_exp_time_t; 00104 typedef image_id apr_os_dso_handle_t; 00105 typedef void* apr_os_shm_t; 00106 00107 #elif defined(NETWARE) 00108 typedef int apr_os_file_t; 00109 typedef DIR apr_os_dir_t; 00110 typedef int apr_os_sock_t; 00111 typedef NXMutex_t apr_os_proc_mutex_t; 00112 typedef NXThreadId_t apr_os_thread_t; 00113 typedef long apr_os_proc_t; 00114 typedef NXKey_t apr_os_threadkey_t; 00115 typedef struct timeval apr_os_imp_time_t; 00116 typedef struct tm apr_os_exp_time_t; 00117 typedef void * apr_os_dso_handle_t; 00118 typedef void* apr_os_shm_t; 00119 00120 #else 00121 /* Any other OS should go above this one. This is the lowest common 00122 * denominator typedefs for all UNIX-like systems. :) 00123 */ 00124 00125 /** Basic OS process mutex structure. */ 00126 struct apr_os_proc_mutex_t { 00127 #if APR_HAS_SYSVSEM_SERIALIZE || APR_HAS_FCNTL_SERIALIZE || APR_HAS_FLOCK_SERIALIZE 00128 /** Value used for SYS V Semaphore, FCNTL and FLOCK serialization */ 00129 int crossproc; 00130 #endif 00131 #if APR_HAS_PROC_PTHREAD_SERIALIZE 00132 /** Value used for PTHREAD serialization */ 00133 pthread_mutex_t *pthread_interproc; 00134 #endif 00135 #if APR_HAS_THREADS 00136 /* If no threads, no need for thread locks */ 00137 #if APR_USE_PTHREAD_SERIALIZE 00138 /** This value is currently unused within APR and Apache */ 00139 pthread_mutex_t *intraproc; 00140 #endif 00141 #endif 00142 }; 00143 00144 typedef int apr_os_file_t; /**< native file */ 00145 typedef DIR apr_os_dir_t; /**< native dir */ 00146 typedef int apr_os_sock_t; /**< native dir */ 00147 typedef struct apr_os_proc_mutex_t apr_os_proc_mutex_t; /**< native proces 00148 * mutex 00149 */ 00150 #if APR_HAS_THREADS && APR_HAVE_PTHREAD_H 00151 typedef pthread_t apr_os_thread_t; /**< native thread */ 00152 typedef pthread_key_t apr_os_threadkey_t; /**< native thread address 00153 * space */ 00154 #endif 00155 typedef pid_t apr_os_proc_t; /**< native pid */ 00156 typedef struct timeval apr_os_imp_time_t; /**< native timeval */ 00157 typedef struct tm apr_os_exp_time_t; /**< native tm */ 00158 /** @var apr_os_dso_handle_t 00159 * native dso types 00160 */ 00161 #if defined(HPUX) || defined(HPUX10) || defined(HPUX11) 00162 #include <dl.h> 00163 typedef shl_t apr_os_dso_handle_t; 00164 #elif defined(DARWIN) 00165 #include <mach-o/dyld.h> 00166 typedef NSModule apr_os_dso_handle_t; 00167 #else 00168 typedef void * apr_os_dso_handle_t; 00169 #endif 00170 typedef void* apr_os_shm_t; /**< native SHM */ 00171 00172 #endif 00173 00174 /** 00175 * @typedef apr_os_sock_info_t 00176 * @brief alias for local OS socket 00177 */ 00178 /** 00179 * everything APR needs to know about an active socket to construct 00180 * an APR socket from it; currently, this is platform-independent 00181 */ 00182 struct apr_os_sock_info_t { 00183 apr_os_sock_t *os_sock; /**< always required */ 00184 struct sockaddr *local; /**< NULL if not yet bound */ 00185 struct sockaddr *remote; /**< NULL if not connected */ 00186 int family; /**< always required (APR_INET, APR_INET6, etc.) */ 00187 int type; /**< always required (SOCK_STREAM, SOCK_DGRAM, etc.) */ 00188 int protocol; /**< 0 or actual protocol (APR_PROTO_SCTP, APR_PROTO_TCP, etc.) */ 00189 }; 00190 00191 typedef struct apr_os_sock_info_t apr_os_sock_info_t; 00192 00193 #if APR_PROC_MUTEX_IS_GLOBAL || defined(DOXYGEN) 00194 /** Opaque global mutex type */ 00195 #define apr_os_global_mutex_t apr_os_proc_mutex_t 00196 /** @return apr_os_global_mutex */ 00197 #define apr_os_global_mutex_get apr_os_proc_mutex_get 00198 #else 00199 /** Thread and process mutex for those platforms where process mutexes 00200 * are not held in threads. 00201 */ 00202 struct apr_os_global_mutex_t { 00203 apr_pool_t *pool; 00204 apr_proc_mutex_t *proc_mutex; 00205 #if APR_HAS_THREADS 00206 apr_thread_mutex_t *thread_mutex; 00207 #endif /* APR_HAS_THREADS */ 00208 }; 00209 typedef struct apr_os_global_mutex_t apr_os_global_mutex_t; 00210 00211 APR_DECLARE(apr_status_t) apr_os_global_mutex_get(apr_os_global_mutex_t *ospmutex, 00212 apr_global_mutex_t *pmutex); 00213 #endif 00214 00215 00216 /** 00217 * convert the file from apr type to os specific type. 00218 * @param thefile The os specific file we are converting to 00219 * @param file The apr file to convert. 00220 * @remark On Unix, it is only possible to get a file descriptor from 00221 * an apr file type. 00222 */ 00223 APR_DECLARE(apr_status_t) apr_os_file_get(apr_os_file_t *thefile, 00224 apr_file_t *file); 00225 00226 /** 00227 * convert the dir from apr type to os specific type. 00228 * @param thedir The os specific dir we are converting to 00229 * @param dir The apr dir to convert. 00230 */ 00231 APR_DECLARE(apr_status_t) apr_os_dir_get(apr_os_dir_t **thedir, 00232 apr_dir_t *dir); 00233 00234 /** 00235 * Convert the socket from an apr type to an OS specific socket 00236 * @param thesock The socket to convert. 00237 * @param sock The os specifc equivelant of the apr socket.. 00238 */ 00239 APR_DECLARE(apr_status_t) apr_os_sock_get(apr_os_sock_t *thesock, 00240 apr_socket_t *sock); 00241 00242 /** 00243 * Convert the proc mutex from os specific type to apr type 00244 * @param ospmutex The os specific proc mutex we are converting to. 00245 * @param pmutex The apr proc mutex to convert. 00246 */ 00247 APR_DECLARE(apr_status_t) apr_os_proc_mutex_get(apr_os_proc_mutex_t *ospmutex, 00248 apr_proc_mutex_t *pmutex); 00249 00250 /** 00251 * Get the exploded time in the platforms native format. 00252 * @param ostime the native time format 00253 * @param aprtime the time to convert 00254 */ 00255 APR_DECLARE(apr_status_t) apr_os_exp_time_get(apr_os_exp_time_t **ostime, 00256 apr_time_exp_t *aprtime); 00257 00258 /** 00259 * Get the imploded time in the platforms native format. 00260 * @param ostime the native time format 00261 * @param aprtime the time to convert 00262 */ 00263 APR_DECLARE(apr_status_t) apr_os_imp_time_get(apr_os_imp_time_t **ostime, 00264 apr_time_t *aprtime); 00265 00266 /** 00267 * convert the shm from apr type to os specific type. 00268 * @param osshm The os specific shm representation 00269 * @param shm The apr shm to convert. 00270 */ 00271 APR_DECLARE(apr_status_t) apr_os_shm_get(apr_os_shm_t *osshm, 00272 apr_shm_t *shm); 00273 00274 #if APR_HAS_THREADS || defined(DOXYGEN) 00275 /** 00276 * @defgroup apr_os_thread Thread portability Routines 00277 * @{ 00278 */ 00279 /** 00280 * convert the thread to os specific type from apr type. 00281 * @param thethd The apr thread to convert 00282 * @param thd The os specific thread we are converting to 00283 */ 00284 APR_DECLARE(apr_status_t) apr_os_thread_get(apr_os_thread_t **thethd, 00285 apr_thread_t *thd); 00286 00287 /** 00288 * convert the thread private memory key to os specific type from an apr type. 00289 * @param thekey The apr handle we are converting from. 00290 * @param key The os specific handle we are converting to. 00291 */ 00292 APR_DECLARE(apr_status_t) apr_os_threadkey_get(apr_os_threadkey_t *thekey, 00293 apr_threadkey_t *key); 00294 00295 /** 00296 * convert the thread from os specific type to apr type. 00297 * @param thd The apr thread we are converting to. 00298 * @param thethd The os specific thread to convert 00299 * @param cont The pool to use if it is needed. 00300 */ 00301 APR_DECLARE(apr_status_t) apr_os_thread_put(apr_thread_t **thd, 00302 apr_os_thread_t *thethd, 00303 apr_pool_t *cont); 00304 00305 /** 00306 * convert the thread private memory key from os specific type to apr type. 00307 * @param key The apr handle we are converting to. 00308 * @param thekey The os specific handle to convert 00309 * @param cont The pool to use if it is needed. 00310 */ 00311 APR_DECLARE(apr_status_t) apr_os_threadkey_put(apr_threadkey_t **key, 00312 apr_os_threadkey_t *thekey, 00313 apr_pool_t *cont); 00314 /** 00315 * Get the thread ID 00316 */ 00317 APR_DECLARE(apr_os_thread_t) apr_os_thread_current(void); 00318 00319 /** 00320 * Compare two thread id's 00321 * @param tid1 1st Thread ID to compare 00322 * @param tid2 2nd Thread ID to compare 00323 */ 00324 APR_DECLARE(int) apr_os_thread_equal(apr_os_thread_t tid1, 00325 apr_os_thread_t tid2); 00326 00327 /** @} */ 00328 #endif /* APR_HAS_THREADS */ 00329 00330 /** 00331 * convert the file from os specific type to apr type. 00332 * @param file The apr file we are converting to. 00333 * @param thefile The os specific file to convert 00334 * @param flags The flags that were used to open this file. 00335 * @param cont The pool to use if it is needed. 00336 * @remark On Unix, it is only possible to put a file descriptor into 00337 * an apr file type. 00338 */ 00339 APR_DECLARE(apr_status_t) apr_os_file_put(apr_file_t **file, 00340 apr_os_file_t *thefile, 00341 apr_int32_t flags, apr_pool_t *cont); 00342 00343 /** 00344 * convert the file from os specific type to apr type. 00345 * @param file The apr file we are converting to. 00346 * @param thefile The os specific pipe to convert 00347 * @param cont The pool to use if it is needed. 00348 * @remark On Unix, it is only possible to put a file descriptor into 00349 * an apr file type. 00350 */ 00351 APR_DECLARE(apr_status_t) apr_os_pipe_put(apr_file_t **file, 00352 apr_os_file_t *thefile, 00353 apr_pool_t *cont); 00354 00355 /** 00356 * convert the file from os specific type to apr type. 00357 * @param file The apr file we are converting to. 00358 * @param thefile The os specific pipe to convert 00359 * @param register_cleanup A cleanup will be registered on the apr_file_t 00360 * to issue apr_file_close(). 00361 * @param cont The pool to use if it is needed. 00362 * @remark On Unix, it is only possible to put a file descriptor into 00363 * an apr file type. 00364 */ 00365 APR_DECLARE(apr_status_t) apr_os_pipe_put_ex(apr_file_t **file, 00366 apr_os_file_t *thefile, 00367 int register_cleanup, 00368 apr_pool_t *cont); 00369 00370 /** 00371 * convert the dir from os specific type to apr type. 00372 * @param dir The apr dir we are converting to. 00373 * @param thedir The os specific dir to convert 00374 * @param cont The pool to use when creating to apr directory. 00375 */ 00376 APR_DECLARE(apr_status_t) apr_os_dir_put(apr_dir_t **dir, 00377 apr_os_dir_t *thedir, 00378 apr_pool_t *cont); 00379 00380 /** 00381 * Convert a socket from the os specific type to the apr type 00382 * @param sock The pool to use. 00383 * @param thesock The socket to convert to. 00384 * @param cont The socket we are converting to an apr type. 00385 * @remark If it is a true socket, it is best to call apr_os_sock_make() 00386 * and provide APR with more information about the socket. 00387 */ 00388 APR_DECLARE(apr_status_t) apr_os_sock_put(apr_socket_t **sock, 00389 apr_os_sock_t *thesock, 00390 apr_pool_t *cont); 00391 00392 /** 00393 * Create a socket from an existing descriptor and local and remote 00394 * socket addresses. 00395 * @param apr_sock The new socket that has been set up 00396 * @param os_sock_info The os representation of the socket handle and 00397 * other characteristics of the socket 00398 * @param cont The pool to use 00399 * @remark If you only know the descriptor/handle or if it isn't really 00400 * a true socket, use apr_os_sock_put() instead. 00401 */ 00402 APR_DECLARE(apr_status_t) apr_os_sock_make(apr_socket_t **apr_sock, 00403 apr_os_sock_info_t *os_sock_info, 00404 apr_pool_t *cont); 00405 00406 /** 00407 * Convert the proc mutex from os specific type to apr type 00408 * @param pmutex The apr proc mutex we are converting to. 00409 * @param ospmutex The os specific proc mutex to convert. 00410 * @param cont The pool to use if it is needed. 00411 */ 00412 APR_DECLARE(apr_status_t) apr_os_proc_mutex_put(apr_proc_mutex_t **pmutex, 00413 apr_os_proc_mutex_t *ospmutex, 00414 apr_pool_t *cont); 00415 00416 /** 00417 * Put the imploded time in the APR format. 00418 * @param aprtime the APR time format 00419 * @param ostime the time to convert 00420 * @param cont the pool to use if necessary 00421 */ 00422 APR_DECLARE(apr_status_t) apr_os_imp_time_put(apr_time_t *aprtime, 00423 apr_os_imp_time_t **ostime, 00424 apr_pool_t *cont); 00425 00426 /** 00427 * Put the exploded time in the APR format. 00428 * @param aprtime the APR time format 00429 * @param ostime the time to convert 00430 * @param cont the pool to use if necessary 00431 */ 00432 APR_DECLARE(apr_status_t) apr_os_exp_time_put(apr_time_exp_t *aprtime, 00433 apr_os_exp_time_t **ostime, 00434 apr_pool_t *cont); 00435 00436 /** 00437 * convert the shared memory from os specific type to apr type. 00438 * @param shm The apr shm representation of osshm 00439 * @param osshm The os specific shm identity 00440 * @param cont The pool to use if it is needed. 00441 * @remark On fork()ed architectures, this is typically nothing more than 00442 * the memory block mapped. On non-fork architectures, this is typically 00443 * some internal handle to pass the mapping from process to process. 00444 */ 00445 APR_DECLARE(apr_status_t) apr_os_shm_put(apr_shm_t **shm, 00446 apr_os_shm_t *osshm, 00447 apr_pool_t *cont); 00448 00449 00450 #if APR_HAS_DSO || defined(DOXYGEN) 00451 /** 00452 * @defgroup apr_os_dso DSO (Dynamic Loading) Portabiliity Routines 00453 * @{ 00454 */ 00455 /** 00456 * convert the dso handle from os specific to apr 00457 * @param dso The apr handle we are converting to 00458 * @param thedso the os specific handle to convert 00459 * @param pool the pool to use if it is needed 00460 */ 00461 APR_DECLARE(apr_status_t) apr_os_dso_handle_put(apr_dso_handle_t **dso, 00462 apr_os_dso_handle_t thedso, 00463 apr_pool_t *pool); 00464 00465 /** 00466 * convert the apr dso handle into an os specific one 00467 * @param aprdso The apr dso handle to convert 00468 * @param dso The os specific dso to return 00469 */ 00470 APR_DECLARE(apr_status_t) apr_os_dso_handle_get(apr_os_dso_handle_t *dso, 00471 apr_dso_handle_t *aprdso); 00472 00473 #if APR_HAS_OS_UUID 00474 /** 00475 * Private: apr-util's apr_uuid module when supported by the platform 00476 */ 00477 APR_DECLARE(apr_status_t) apr_os_uuid_get(unsigned char *uuid_data); 00478 #endif 00479 00480 /** @} */ 00481 #endif /* APR_HAS_DSO */ 00482 00483 00484 /** 00485 * Get the name of the system default characer set. 00486 * @param pool the pool to allocate the name from, if needed 00487 */ 00488 APR_DECLARE(const char*) apr_os_default_encoding(apr_pool_t *pool); 00489 00490 00491 /** 00492 * Get the name of the current locale character set. 00493 * @param pool the pool to allocate the name from, if needed 00494 * @remark Defers to apr_os_default_encoding if the current locale's 00495 * data can't be retreved on this system. 00496 */ 00497 APR_DECLARE(const char*) apr_os_locale_encoding(apr_pool_t *pool); 00498 00499 /** @} */ 00500 00501 #ifdef __cplusplus 00502 } 00503 #endif 00504 00505 #endif /* ! APR_PORTABLE_H */

Generated on Thu Sep 16 13:47:10 2004 for Apache Portable Runtime by doxygen 1.3.7