aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llcommon/llapr.cpp
diff options
context:
space:
mode:
authorJacek Antonelli2009-04-30 13:04:20 -0500
committerJacek Antonelli2009-04-30 13:07:16 -0500
commitca8149ca6d157eb4b5fc8ba0e5ba3a6e56f72e7e (patch)
tree8348301d0ac44a524f1819b777686bf086907d76 /linden/indra/llcommon/llapr.cpp
parentSecond Life viewer sources 1.22.11 (diff)
downloadmeta-impy-ca8149ca6d157eb4b5fc8ba0e5ba3a6e56f72e7e.zip
meta-impy-ca8149ca6d157eb4b5fc8ba0e5ba3a6e56f72e7e.tar.gz
meta-impy-ca8149ca6d157eb4b5fc8ba0e5ba3a6e56f72e7e.tar.bz2
meta-impy-ca8149ca6d157eb4b5fc8ba0e5ba3a6e56f72e7e.tar.xz
Second Life viewer sources 1.23.0-RC
Diffstat (limited to '')
-rw-r--r--linden/indra/llcommon/llapr.cpp505
1 files changed, 391 insertions, 114 deletions
diff --git a/linden/indra/llcommon/llapr.cpp b/linden/indra/llcommon/llapr.cpp
index 589d3f5..82530b1 100644
--- a/linden/indra/llcommon/llapr.cpp
+++ b/linden/indra/llcommon/llapr.cpp
@@ -19,7 +19,8 @@
19 * There are special exceptions to the terms and conditions of the GPL as 19 * There are special exceptions to the terms and conditions of the GPL as
20 * it is applied to this Source Code. View the full text of the exception 20 * it is applied to this Source Code. View the full text of the exception
21 * in the file doc/FLOSS-exception.txt in this software distribution, or 21 * in the file doc/FLOSS-exception.txt in this software distribution, or
22 * online at http://secondlifegrid.net/programs/open_source/licensing/flossexception 22 * online at
23 * http://secondlifegrid.net/programs/open_source/licensing/flossexception
23 * 24 *
24 * By copying, modifying or distributing this software, you acknowledge 25 * By copying, modifying or distributing this software, you acknowledge
25 * that you have read and understood your obligations described above, 26 * that you have read and understood your obligations described above,
@@ -35,8 +36,10 @@
35#include "llapr.h" 36#include "llapr.h"
36 37
37apr_pool_t *gAPRPoolp = NULL; // Global APR memory pool 38apr_pool_t *gAPRPoolp = NULL; // Global APR memory pool
39LLVolatileAPRPool *LLAPRFile::sAPRFilePoolp = NULL ; //global volatile APR memory pool.
38apr_thread_mutex_t *gLogMutexp = NULL; 40apr_thread_mutex_t *gLogMutexp = NULL;
39 41
42const S32 FULL_VOLATILE_APR_POOL = 1024 ; //number of references to LLVolatileAPRPool
40 43
41void ll_init_apr() 44void ll_init_apr()
42{ 45{
@@ -45,10 +48,15 @@ void ll_init_apr()
45 // Initialize APR and create the global pool 48 // Initialize APR and create the global pool
46 apr_initialize(); 49 apr_initialize();
47 apr_pool_create(&gAPRPoolp, NULL); 50 apr_pool_create(&gAPRPoolp, NULL);
48 51
49 // Initialize the logging mutex 52 // Initialize the logging mutex
50 apr_thread_mutex_create(&gLogMutexp, APR_THREAD_MUTEX_UNNESTED, gAPRPoolp); 53 apr_thread_mutex_create(&gLogMutexp, APR_THREAD_MUTEX_UNNESTED, gAPRPoolp);
51 } 54 }
55
56 if(!LLAPRFile::sAPRFilePoolp)
57 {
58 LLAPRFile::sAPRFilePoolp = new LLVolatileAPRPool() ;
59 }
52} 60}
53 61
54 62
@@ -69,31 +77,127 @@ void ll_cleanup_apr()
69 apr_pool_destroy(gAPRPoolp); 77 apr_pool_destroy(gAPRPoolp);
70 gAPRPoolp = NULL; 78 gAPRPoolp = NULL;
71 } 79 }
80 if (LLAPRFile::sAPRFilePoolp)
81 {
82 delete LLAPRFile::sAPRFilePoolp ;
83 LLAPRFile::sAPRFilePoolp = NULL ;
84 }
72 apr_terminate(); 85 apr_terminate();
73} 86}
74 87
75// 88//
89//
76//LLAPRPool 90//LLAPRPool
77// 91//
78LLAPRPool::LLAPRPool(apr_pool_t *parent, apr_size_t size) 92LLAPRPool::LLAPRPool(apr_pool_t *parent, apr_size_t size, BOOL releasePoolFlag)
79{ 93{
80 mStatus = apr_pool_create(&mPool, parent); 94 mParent = parent ;
95 mReleasePoolFlag = releasePoolFlag ;
96 mMaxSize = size ;
97 mPool = NULL ;
98
99 createAPRPool() ;
100}
101
102LLAPRPool::~LLAPRPool()
103{
104 releaseAPRPool() ;
105}
81 106
82 if(size > 0) //size is the number of blocks (which is usually 4K), NOT bytes. 107void LLAPRPool::createAPRPool()
108{
109 if(mPool)
110 {
111 return ;
112 }
113
114 mStatus = apr_pool_create(&mPool, mParent);
115 ll_apr_warn_status(mStatus) ;
116
117 if(mMaxSize > 0) //size is the number of blocks (which is usually 4K), NOT bytes.
83 { 118 {
84 apr_allocator_t *allocator = apr_pool_allocator_get(mPool); 119 apr_allocator_t *allocator = apr_pool_allocator_get(mPool);
85 if (allocator) 120 if (allocator)
86 { 121 {
87 apr_allocator_max_free_set(allocator, size) ; 122 apr_allocator_max_free_set(allocator, mMaxSize) ;
88 } 123 }
89 } 124 }
90} 125}
91 126
92LLAPRPool::~LLAPRPool() 127void LLAPRPool::releaseAPRPool()
128{
129 if(!mPool)
130 {
131 return ;
132 }
133
134 if(!mParent || mReleasePoolFlag)
135 {
136 apr_pool_destroy(mPool) ;
137 mPool = NULL ;
138 }
139}
140
141apr_pool_t* LLAPRPool::getAPRPool()
93{ 142{
94 apr_pool_destroy(mPool) ; 143 if(!mPool)
144 {
145 createAPRPool() ;
146 }
147
148 return mPool ;
149}
150LLVolatileAPRPool::LLVolatileAPRPool(apr_pool_t *parent, apr_size_t size, BOOL releasePoolFlag)
151 : LLAPRPool(parent, size, releasePoolFlag)
152{
153 mNumActiveRef = 0 ;
154 mNumTotalRef = 0 ;
95} 155}
96 156
157apr_pool_t* LLVolatileAPRPool::getVolatileAPRPool()
158{
159 mNumTotalRef++ ;
160 mNumActiveRef++ ;
161 return getAPRPool() ;
162}
163
164void LLVolatileAPRPool::clearVolatileAPRPool()
165{
166 if(mNumActiveRef > 0)
167 {
168 mNumActiveRef--;
169 if(mNumActiveRef < 1)
170 {
171 if(isFull())
172 {
173 mNumTotalRef = 0 ;
174
175 //destroy the apr_pool.
176 releaseAPRPool() ;
177 }
178 else
179 {
180 //This does not actually free the memory,
181 //it just allows the pool to re-use this memory for the next allocation.
182 apr_pool_clear(mPool) ;
183 }
184 }
185 }
186 else
187 {
188 llassert_always(mNumActiveRef > 0) ;
189 }
190
191 //paranoia check if the pool is jammed.
192 //will remove the check before going to release.
193 llassert_always(mNumTotalRef < (FULL_VOLATILE_APR_POOL << 2)) ;
194}
195
196BOOL LLVolatileAPRPool::isFull()
197{
198 return mNumTotalRef > FULL_VOLATILE_APR_POOL ;
199}
200//---------------------------------------------------------------------
97// 201//
98// LLScopedLock 202// LLScopedLock
99// 203//
@@ -132,9 +236,8 @@ void LLScopedLock::unlock()
132 } 236 }
133} 237}
134 238
135// 239//---------------------------------------------------------------------
136// Misc functions 240
137//
138bool ll_apr_warn_status(apr_status_t status) 241bool ll_apr_warn_status(apr_status_t status)
139{ 242{
140 if(APR_SUCCESS == status) return false; 243 if(APR_SUCCESS == status) return false;
@@ -150,55 +253,110 @@ void ll_apr_assert_status(apr_status_t status)
150 llassert(ll_apr_warn_status(status) == false); 253 llassert(ll_apr_warn_status(status) == false);
151} 254}
152 255
153// File I/O 256//---------------------------------------------------------------------
154apr_file_t* ll_apr_file_open(const std::string& filename, apr_int32_t flags, S32* sizep, apr_pool_t* pool) 257//
258// LLAPRFile functions
259//
260LLAPRFile::LLAPRFile()
261{
262 mFile = NULL ;
263 mCurrentFilePoolp = NULL ;
264}
265LLAPRFile::~LLAPRFile()
266{
267 close() ;
268}
269
270apr_status_t LLAPRFile::close()
271{
272 apr_status_t ret = APR_SUCCESS ;
273 if(mFile)
274 {
275 ret = apr_file_close(mFile);
276 mFile = NULL ;
277 }
278
279 if(mCurrentFilePoolp)
280 {
281 mCurrentFilePoolp->clearVolatileAPRPool() ;
282 mCurrentFilePoolp = NULL ;
283 }
284
285 return ret ;
286}
287
288apr_status_t LLAPRFile::open(LLVolatileAPRPool* pool, const std::string& filename, apr_int32_t flags, S32* sizep)
289{
290 apr_status_t s ;
291 s = open(filename, flags, pool ? pool->getVolatileAPRPool() : NULL, sizep) ;
292
293 if(!mCurrentFilePoolp)
294 {
295 mCurrentFilePoolp = pool ;
296
297 if(!mFile)
298 {
299 close() ;
300 }
301 }
302
303 return s ;
304}
305apr_status_t LLAPRFile::open(const std::string& filename, apr_int32_t flags, apr_pool_t* pool, S32* sizep)
155{ 306{
156 apr_file_t* apr_file;
157 apr_status_t s; 307 apr_status_t s;
158 if (pool == NULL) pool = gAPRPoolp; 308
159 s = apr_file_open(&apr_file, filename.c_str(), flags, APR_OS_DEFAULT, pool); 309 //check if already open some file
160 if (s != APR_SUCCESS) 310 llassert_always(!mFile) ;
311 llassert_always(!mCurrentFilePoolp) ;
312
313 s = apr_file_open(&mFile, filename.c_str(), flags, APR_OS_DEFAULT, getAPRFilePool(pool));
314 if (s != APR_SUCCESS || !mFile)
161 { 315 {
316 mFile = NULL ;
317 close() ;
162 if (sizep) 318 if (sizep)
163 { 319 {
164 *sizep = 0; 320 *sizep = 0;
165 } 321 }
166 return NULL; 322 return s;
167 } 323 }
168 324
169 if (sizep) 325 if (sizep)
170 { 326 {
171 S32 file_size = 0; 327 S32 file_size = 0;
172 apr_off_t offset = 0; 328 apr_off_t offset = 0;
173 if (apr_file_seek(apr_file, APR_END, &offset) == APR_SUCCESS) 329 if (apr_file_seek(mFile, APR_END, &offset) == APR_SUCCESS)
174 { 330 {
175 llassert_always(offset <= 0x7fffffff); 331 llassert_always(offset <= 0x7fffffff);
176 file_size = (S32)offset; 332 file_size = (S32)offset;
177 offset = 0; 333 offset = 0;
178 apr_file_seek(apr_file, APR_SET, &offset); 334 apr_file_seek(mFile, APR_SET, &offset);
179 } 335 }
180 *sizep = file_size; 336 *sizep = file_size;
181 } 337 }
182 338
183 return apr_file; 339 return s;
184} 340}
185apr_file_t* ll_apr_file_open(const std::string& filename, apr_int32_t flags, S32* sizep) 341
186{ 342apr_pool_t* LLAPRFile::getAPRFilePool(apr_pool_t* pool)
187 return ll_apr_file_open(filename, flags, sizep, NULL); 343{
188} 344 if(!pool)
189apr_file_t* ll_apr_file_open(const std::string& filename, apr_int32_t flags, apr_pool_t* pool) 345 {
190{ 346 mCurrentFilePoolp = sAPRFilePoolp ;
191 return ll_apr_file_open(filename, flags, NULL, pool); 347 return mCurrentFilePoolp->getVolatileAPRPool() ;
192} 348 }
193apr_file_t* ll_apr_file_open(const std::string& filename, apr_int32_t flags) 349
194{ 350 return pool ;
195 return ll_apr_file_open(filename, flags, NULL, NULL);
196} 351}
197 352
198S32 ll_apr_file_read(apr_file_t* apr_file, void *buf, S32 nbytes) 353// File I/O
354S32 LLAPRFile::read(void *buf, S32 nbytes)
199{ 355{
356 llassert_always(mFile) ;
357
200 apr_size_t sz = nbytes; 358 apr_size_t sz = nbytes;
201 apr_status_t s = apr_file_read(apr_file, buf, &sz); 359 apr_status_t s = apr_file_read(mFile, buf, &sz);
202 if (s != APR_SUCCESS) 360 if (s != APR_SUCCESS)
203 { 361 {
204 return 0; 362 return 0;
@@ -210,165 +368,273 @@ S32 ll_apr_file_read(apr_file_t* apr_file, void *buf, S32 nbytes)
210 } 368 }
211} 369}
212 370
213S32 ll_apr_file_read_ex(const std::string& filename, apr_pool_t* pool, void *buf, S32 offset, S32 nbytes) 371S32 LLAPRFile::write(const void *buf, S32 nbytes)
214{ 372{
215 if (pool == NULL) pool = gAPRPoolp; 373 llassert_always(mFile) ;
216 apr_file_t* filep = ll_apr_file_open(filename, APR_READ|APR_BINARY, pool); 374
217 if (!filep) 375 apr_size_t sz = nbytes;
376 apr_status_t s = apr_file_write(mFile, buf, &sz);
377 if (s != APR_SUCCESS)
218 { 378 {
219 return 0; 379 return 0;
220 } 380 }
221 S32 off;
222 if (offset < 0)
223 off = ll_apr_file_seek(filep, APR_END, 0);
224 else 381 else
225 off = ll_apr_file_seek(filep, APR_SET, offset);
226 S32 bytes_read;
227 if (off < 0)
228 { 382 {
229 bytes_read = 0; 383 llassert_always(sz <= 0x7fffffff);
384 return (S32)sz;
230 } 385 }
231 else 386}
387
388S32 LLAPRFile::seek(apr_seek_where_t where, S32 offset)
389{
390 return LLAPRFile::seek(mFile, where, offset) ;
391}
392
393//
394//*******************************************************************************************************************************
395//static components of LLAPRFile
396//
397
398//static
399apr_status_t LLAPRFile::close(apr_file_t* file_handle, LLVolatileAPRPool* pool)
400{
401 apr_status_t ret = APR_SUCCESS ;
402 if(file_handle)
232 { 403 {
233 bytes_read = ll_apr_file_read(filep, buf, nbytes ); 404 ret = apr_file_close(file_handle);
405 file_handle = NULL ;
234 } 406 }
235 apr_file_close(filep);
236 407
237 return bytes_read; 408 if(pool)
409 {
410 pool->clearVolatileAPRPool() ;
411 }
412
413 return ret ;
238} 414}
239 415
240S32 ll_apr_file_write(apr_file_t* apr_file, const void *buf, S32 nbytes) 416//static
417apr_file_t* LLAPRFile::open(const std::string& filename, LLVolatileAPRPool* pool, apr_int32_t flags)
241{ 418{
242 apr_size_t sz = nbytes; 419 apr_status_t s;
243 apr_status_t s = apr_file_write(apr_file, buf, &sz); 420 apr_file_t* file_handle ;
421
422 pool = pool ? pool : LLAPRFile::sAPRFilePoolp ;
423
424 s = apr_file_open(&file_handle, filename.c_str(), flags, APR_OS_DEFAULT, pool->getVolatileAPRPool());
425 if (s != APR_SUCCESS || !file_handle)
426 {
427 file_handle = NULL ;
428 close(file_handle, pool) ;
429 return NULL;
430 }
431
432 return file_handle ;
433}
434
435//static
436S32 LLAPRFile::seek(apr_file_t* file_handle, apr_seek_where_t where, S32 offset)
437{
438 if(!file_handle)
439 {
440 return -1 ;
441 }
442
443 apr_status_t s;
444 apr_off_t apr_offset;
445 if (offset >= 0)
446 {
447 apr_offset = (apr_off_t)offset;
448 s = apr_file_seek(file_handle, where, &apr_offset);
449 }
450 else
451 {
452 apr_offset = 0;
453 s = apr_file_seek(file_handle, APR_END, &apr_offset);
454 }
244 if (s != APR_SUCCESS) 455 if (s != APR_SUCCESS)
245 { 456 {
457 return -1;
458 }
459 else
460 {
461 llassert_always(apr_offset <= 0x7fffffff);
462 return (S32)apr_offset;
463 }
464}
465
466//static
467S32 LLAPRFile::readEx(const std::string& filename, void *buf, S32 offset, S32 nbytes, LLVolatileAPRPool* pool)
468{
469 //*****************************************
470 apr_file_t* file_handle = open(filename, pool, APR_READ|APR_BINARY);
471 //*****************************************
472 if (!file_handle)
473 {
246 return 0; 474 return 0;
247 } 475 }
476
477 S32 off;
478 if (offset < 0)
479 off = LLAPRFile::seek(file_handle, APR_END, 0);
248 else 480 else
481 off = LLAPRFile::seek(file_handle, APR_SET, offset);
482
483 apr_size_t bytes_read;
484 if (off < 0)
249 { 485 {
250 llassert_always(sz <= 0x7fffffff); 486 bytes_read = 0;
251 return (S32)sz;
252 } 487 }
488 else
489 {
490 bytes_read = nbytes ;
491 apr_status_t s = apr_file_read(file_handle, buf, &bytes_read);
492 if (s != APR_SUCCESS)
493 {
494 bytes_read = 0;
495 }
496 else
497 {
498 llassert_always(bytes_read <= 0x7fffffff);
499 }
500 }
501
502 //*****************************************
503 close(file_handle, pool) ;
504 //*****************************************
505 return (S32)bytes_read;
253} 506}
254 507
255S32 ll_apr_file_write_ex(const std::string& filename, apr_pool_t* pool, void *buf, S32 offset, S32 nbytes) 508//static
509S32 LLAPRFile::writeEx(const std::string& filename, void *buf, S32 offset, S32 nbytes, LLVolatileAPRPool* pool)
256{ 510{
257 if (pool == NULL) pool = gAPRPoolp;
258 apr_int32_t flags = APR_CREATE|APR_WRITE|APR_BINARY; 511 apr_int32_t flags = APR_CREATE|APR_WRITE|APR_BINARY;
259 if (offset < 0) 512 if (offset < 0)
260 { 513 {
261 flags |= APR_APPEND; 514 flags |= APR_APPEND;
262 offset = 0; 515 offset = 0;
263 } 516 }
264 apr_file_t* filep = ll_apr_file_open(filename, flags, pool); 517
265 if (!filep) 518 //*****************************************
519 apr_file_t* file_handle = open(filename, pool, flags);
520 //*****************************************
521 if (!file_handle)
266 { 522 {
267 return 0; 523 return 0;
268 } 524 }
525
269 if (offset > 0) 526 if (offset > 0)
270 { 527 {
271 offset = ll_apr_file_seek(filep, APR_SET, offset); 528 offset = LLAPRFile::seek(file_handle, APR_SET, offset);
272 } 529 }
273 S32 bytes_written; 530
531 apr_size_t bytes_written;
274 if (offset < 0) 532 if (offset < 0)
275 { 533 {
276 bytes_written = 0; 534 bytes_written = 0;
277 } 535 }
278 else 536 else
279 { 537 {
280 bytes_written = ll_apr_file_write(filep, buf, nbytes ); 538 bytes_written = nbytes ;
539 apr_status_t s = apr_file_write(file_handle, buf, &bytes_written);
540 if (s != APR_SUCCESS)
541 {
542 bytes_written = 0;
543 }
544 else
545 {
546 llassert_always(bytes_written <= 0x7fffffff);
547 }
281 } 548 }
282 apr_file_close(filep);
283 549
284 return bytes_written; 550 //*****************************************
285} 551 LLAPRFile::close(file_handle, pool);
552 //*****************************************
286 553
287S32 ll_apr_file_seek(apr_file_t* apr_file, apr_seek_where_t where, S32 offset) 554 return (S32)bytes_written;
288{
289 apr_status_t s;
290 apr_off_t apr_offset;
291 if (offset >= 0)
292 {
293 apr_offset = (apr_off_t)offset;
294 s = apr_file_seek(apr_file, where, &apr_offset);
295 }
296 else
297 {
298 apr_offset = 0;
299 s = apr_file_seek(apr_file, APR_END, &apr_offset);
300 }
301 if (s != APR_SUCCESS)
302 {
303 return -1;
304 }
305 else
306 {
307 llassert_always(apr_offset <= 0x7fffffff);
308 return (S32)apr_offset;
309 }
310} 555}
311 556
312bool ll_apr_file_remove(const std::string& filename, apr_pool_t* pool) 557//static
558bool LLAPRFile::remove(const std::string& filename, LLVolatileAPRPool* pool)
313{ 559{
314 apr_status_t s; 560 apr_status_t s;
315 if (pool == NULL) pool = gAPRPoolp; 561
316 s = apr_file_remove(filename.c_str(), pool); 562 pool = pool ? pool : LLAPRFile::sAPRFilePoolp ;
563 s = apr_file_remove(filename.c_str(), pool->getVolatileAPRPool());
564 pool->clearVolatileAPRPool() ;
565
317 if (s != APR_SUCCESS) 566 if (s != APR_SUCCESS)
318 { 567 {
319 LL_DEBUGS("APR") << "ll_apr_file_remove failed on file: " << filename << LL_ENDL; 568 LL_DEBUGS("APR") << "LLAPRFile::remove failed on file: " << filename << LL_ENDL;
320 ll_apr_warn_status(s); 569 ll_apr_warn_status(s);
321 return false; 570 return false;
322 } 571 }
323 return true; 572 return true;
324} 573}
325 574
326bool ll_apr_file_rename(const std::string& filename, const std::string& newname, apr_pool_t* pool) 575//static
576bool LLAPRFile::rename(const std::string& filename, const std::string& newname, LLVolatileAPRPool* pool)
327{ 577{
328 apr_status_t s; 578 apr_status_t s;
329 if (pool == NULL) pool = gAPRPoolp; 579
330 s = apr_file_rename(filename.c_str(), newname.c_str(), pool); 580 pool = pool ? pool : LLAPRFile::sAPRFilePoolp ;
581 s = apr_file_rename(filename.c_str(), newname.c_str(), pool->getVolatileAPRPool());
582 pool->clearVolatileAPRPool() ;
583
331 if (s != APR_SUCCESS) 584 if (s != APR_SUCCESS)
332 { 585 {
333 LL_DEBUGS("APR") << "ll_apr_file_rename failed on file: " << filename << LL_ENDL; 586 LL_DEBUGS("APR") << "LLAPRFile::rename failed on file: " << filename << LL_ENDL;
334 ll_apr_warn_status(s); 587 ll_apr_warn_status(s);
335 return false; 588 return false;
336 } 589 }
337 return true; 590 return true;
338} 591}
339 592
340bool ll_apr_file_exists(const std::string& filename, apr_pool_t* pool) 593//static
594bool LLAPRFile::isExist(const std::string& filename, LLVolatileAPRPool* pool, apr_int32_t flags)
341{ 595{
342 apr_file_t* apr_file; 596 apr_file_t* apr_file;
343 apr_status_t s; 597 apr_status_t s;
344 if (pool == NULL) pool = gAPRPoolp; 598
345 s = apr_file_open(&apr_file, filename.c_str(), APR_READ, APR_OS_DEFAULT, pool); 599 pool = pool ? pool : LLAPRFile::sAPRFilePoolp ;
600 s = apr_file_open(&apr_file, filename.c_str(), flags, APR_OS_DEFAULT, pool->getVolatileAPRPool());
601
346 if (s != APR_SUCCESS || !apr_file) 602 if (s != APR_SUCCESS || !apr_file)
347 { 603 {
604 pool->clearVolatileAPRPool() ;
348 return false; 605 return false;
349 } 606 }
350 else 607 else
351 { 608 {
352 apr_file_close(apr_file); 609 apr_file_close(apr_file) ;
610 pool->clearVolatileAPRPool() ;
353 return true; 611 return true;
354 } 612 }
355} 613}
356 614
357S32 ll_apr_file_size(const std::string& filename, apr_pool_t* pool) 615//static
616S32 LLAPRFile::size(const std::string& filename, LLVolatileAPRPool* pool)
358{ 617{
359 apr_file_t* apr_file; 618 apr_file_t* apr_file;
360 apr_finfo_t info; 619 apr_finfo_t info;
361 apr_status_t s; 620 apr_status_t s;
362 if (pool == NULL) pool = gAPRPoolp; 621
363 s = apr_file_open(&apr_file, filename.c_str(), APR_READ, APR_OS_DEFAULT, pool); 622 pool = pool ? pool : LLAPRFile::sAPRFilePoolp ;
623 s = apr_file_open(&apr_file, filename.c_str(), APR_READ, APR_OS_DEFAULT, pool->getVolatileAPRPool());
624
364 if (s != APR_SUCCESS || !apr_file) 625 if (s != APR_SUCCESS || !apr_file)
365 { 626 {
627 pool->clearVolatileAPRPool() ;
628
366 return 0; 629 return 0;
367 } 630 }
368 else 631 else
369 { 632 {
370 apr_status_t s = apr_file_info_get(&info, APR_FINFO_SIZE, apr_file); 633 apr_status_t s = apr_file_info_get(&info, APR_FINFO_SIZE, apr_file);
371 apr_file_close(apr_file); 634
635 apr_file_close(apr_file) ;
636 pool->clearVolatileAPRPool() ;
637
372 if (s == APR_SUCCESS) 638 if (s == APR_SUCCESS)
373 { 639 {
374 return (S32)info.size; 640 return (S32)info.size;
@@ -380,31 +646,42 @@ S32 ll_apr_file_size(const std::string& filename, apr_pool_t* pool)
380 } 646 }
381} 647}
382 648
383bool ll_apr_dir_make(const std::string& dirname, apr_pool_t* pool) 649//static
650bool LLAPRFile::makeDir(const std::string& dirname, LLVolatileAPRPool* pool)
384{ 651{
385 apr_status_t s; 652 apr_status_t s;
386 if (pool == NULL) pool = gAPRPoolp; 653
387 s = apr_dir_make(dirname.c_str(), APR_FPROT_OS_DEFAULT, pool); 654 pool = pool ? pool : LLAPRFile::sAPRFilePoolp ;
655 s = apr_dir_make(dirname.c_str(), APR_FPROT_OS_DEFAULT, pool->getVolatileAPRPool());
656 pool->clearVolatileAPRPool() ;
657
388 if (s != APR_SUCCESS) 658 if (s != APR_SUCCESS)
389 { 659 {
390 LL_DEBUGS("APR") << "ll_apr_dir_make failed on file: " << dirname << LL_ENDL; 660 LL_DEBUGS("APR") << "LLAPRFile::makeDir failed on file: " << dirname << LL_ENDL;
391 ll_apr_warn_status(s); 661 ll_apr_warn_status(s);
392 return false; 662 return false;
393 } 663 }
394 return true; 664 return true;
395} 665}
396 666
397bool ll_apr_dir_remove(const std::string& dirname, apr_pool_t* pool) 667//static
668bool LLAPRFile::removeDir(const std::string& dirname, LLVolatileAPRPool* pool)
398{ 669{
399 apr_status_t s; 670 apr_status_t s;
400 if (pool == NULL) pool = gAPRPoolp; 671
401 s = apr_file_remove(dirname.c_str(), pool); 672 pool = pool ? pool : LLAPRFile::sAPRFilePoolp ;
673 s = apr_file_remove(dirname.c_str(), pool->getVolatileAPRPool());
674 pool->clearVolatileAPRPool() ;
675
402 if (s != APR_SUCCESS) 676 if (s != APR_SUCCESS)
403 { 677 {
404 LL_DEBUGS("APR") << "ll_apr_dir_remove failed on file: " << dirname << LL_ENDL; 678 LL_DEBUGS("APR") << "LLAPRFile::removeDir failed on file: " << dirname << LL_ENDL;
405 ll_apr_warn_status(s); 679 ll_apr_warn_status(s);
406 return false; 680 return false;
407 } 681 }
408 return true; 682 return true;
409} 683}
410 684//
685//end of static components of LLAPRFile
686//*******************************************************************************************************************************
687//