00001
#ifndef FileDescPool_H
00002
#define FileDescPool_H
00003
00004
#include "PtMutex.h"
00005
#include "PtCondition.h"
00006
#include <list>
00007
#include <string>
00008
#include <set>
00009
#include <sys/types.h>
00010
#include <sys/stat.h>
00011
#include <fcntl.h>
00012
00013 BOREALIS_NAMESPACE_BEGIN;
00014
00015 class FileDescPool
00016 {
00017
public:
00018
00019
00020
FileDescPool(string filepath,
int openFlags,
int minFDs,
int maxFDs)
00021
throw (std::exception,
00022
SmIllegalParameterValueException,
00023
SmFilesystemException);
00024
00025
00026
00027
FileDescPool(string filepath,
int openFlags, mode_t permissions,
int minFDs,
int maxFDs)
00028
throw (std::exception,
00029
SmIllegalParameterValueException,
00030
SmFilesystemException);
00031
00032
virtual ~FileDescPool();
00033
00034
unsigned int getMinFDs()
00035
throw (std::exception);
00036
00037
unsigned int getMaxFDs()
00038
throw (std::exception);
00039
00040
unsigned int getTotalFDsInPool()
00041
throw (std::exception);
00042
00043
unsigned int getNumLeasedFDs()
00044
throw (std::exception);
00045
00046
00047
00048
void setFDLimits(
unsigned int newMinFDs,
unsigned int newMaxFDs)
00049
throw (std::exception);
00050
00051
00052
00053
00054
00055
00056
int acquireFdBlocking()
00057
throw (std::exception,
00058
SmClosedException);
00059
00060
00061
00062
00063
int acquireFdNonBlocking()
00064
throw (std::exception);
00065
00066
00067
void releaseFd(
int fd)
00068
throw (std::exception);
00069
00070
00071
00072
00073
00074
00075
void closeAll()
00076
throw (std::exception);
00077
00078
private:
00079
00080
00081
00082
void adjustFdCount(
int numDesiredFDs)
00083
throw (std::exception);
00084
00085
00086
void deallocateOneFD()
00087
throw (std::exception);
00088
00089
00090
void allocateOneFD()
00091
throw (std::exception);
00092
00093
PtMutex _mtx;
00094
PtCondition _condAvailableFD;
00095 list<int> _freeFDs;
00096 set<int> _leasedFDs;
00097
00098 string _filepath;
00099
int _openFlags;
00100
unsigned int _minFDs;
00101
unsigned int _maxFDs;
00102
00103 mode_t _permissions;
00104
bool _permissionsSet;
00105 };
00106
00107 BOREALIS_NAMESPACE_END;
00108
00109
#endif