00001
#ifndef FdMultiPool_H
00002
#define FdMultiPool_H
00003
00004
#include "common.h"
00005
#include "Exceptions.h"
00006
#include "PtMutex.h"
00007
#include <map>
00008
#include <list>
00009
#include <set>
00010
#include <string>
00011
#include <fcntl.h>
00012
00013 BOREALIS_NAMESPACE_BEGIN;
00014
00015
00016
00017
00018
00019
00020 class FdMultiPool
00021 {
00022
public:
00023
FdMultiPool(
int maxFdsInPool)
00024
throw (std::exception);
00025
00026
virtual ~FdMultiPool();
00027
00028
00029
00030
00031
void registerFile(string pathname,
int openFlags)
00032
throw (std::exception);
00033
00034
00035
void registerFile(string pathname,
int openFlags, mode_t permissions)
00036
throw (std::exception);
00037
00038
00039
00040
void close()
00041
throw (std::exception);
00042
00043
00044
00045
00046
00047
00048
00049
00050
int acquireFdNonBlocking(string pathname)
00051
throw (std::exception);
00052
00053
void releaseFd(string pathname,
int releasedFd)
00054
throw (std::exception);
00055
00056
00057
00058
void printDebugInfo(ostream & o)
00059
throw (std::exception);
00060
00061
private:
00062
PtMutex _mtx;
00063
00064
const int _maxFdsInPool;
00065
bool _closed;
00066
00067
00068
struct FileInfo
00069 {
00070
int _openFlags;
00071
00072 mode_t _permissions;
00073
bool _permissionsSpecified;
00074
00075 set<int> _leasedFds;
00076 list<int> _nonLeasedFds;
00077 };
00078
00079 map<string, FileInfo> _registeredFiles;
00080
00081
00082
00083
00084
int openFile(string pathname)
00085
throw (std::exception);
00086
00087
00088
00089
void evictOneFd()
00090
throw (std::exception);
00091
00092
00093
00094
int getNumOpenFds()
00095
throw (std::exception);
00096 };
00097
00098 BOREALIS_NAMESPACE_END;
00099
00100
#endif