FileHandle.hh
Go to the documentation of this file.
1 //
2 // Copyright (c) 2020 Fraunhofer Institute for Applied Information Technology (FIT)
3 // Network Research Group (NET)
4 // Schloss Birlinghoven, 53754 Sankt Augustin, GERMANY
5 // Contact: support@wiback.org
6 //
7 // This file is part of the SENF code tree.
8 // It is licensed under the 3-clause BSD License (aka New BSD License).
9 // See LICENSE.txt in the top level directory for details or visit
10 // https://opensource.org/licenses/BSD-3-Clause
11 //
12 
13 
48 #ifndef HH_SENF_Socket_FileHandle_
49 #define HH_SENF_Socket_FileHandle_ 1
50 
51 // Custom includes
52 #include <senf/Utils/Cpp11Support/smart_ptr.hh>
53 #include <senf/Utils/safe_bool.hh>
55 
56 //#include "FileHandle.mpp"
57 //-/////////////////////////////////////////////////////////////////////////////////////////////////
58 #include "FileHandle.ih"
59 
60 namespace senf {
61 
64  class FileHandleAccess
65  {
66  protected:
67  static void * extraPtr(FileHandle const & fh);
68  static void extraPtr(FileHandle fh, void * ptr);
69  };
70 
72  //\{
73 
103  class FileHandle
104  : public safe_bool<FileHandle>
105  {
106  public:
107  //-////////////////////////////////////////////////////////////////////////
108  // Types
109 
110  //-////////////////////////////////////////////////////////////////////////
112  //\{
113 
114  FileHandle();
115  ~FileHandle();
116 
117  // my default constructor
118  // default copy constructor
119  // default copy assignment
120  // default destructor
121 
122  // no conversion constructors
123 
124  //\}
125  //-////////////////////////////////////////////////////////////////////////
126 
127  void close();
128 
129  void terminate();
130 
131  bool readable() const;
132  bool waitReadable(senf::ClockService::clock_type timeout = senf::ClockService::clock_type(-1)) const;
136 
140  bool writeable() const;
141  bool waitWriteable(senf::ClockService::clock_type timeout = senf::ClockService::clock_type(-1)) const;
145 
149  bool oobReadable() const;
150  bool waitOOBReadable(senf::ClockService::clock_type timeout = senf::ClockService::clock_type(-1)) const;
154 
159  bool blocking() const;
160  void blocking(bool status);
161 
162  bool eof() const;
163 
171  bool valid() const;
172 
175  bool boolean_test() const;
176 
181  int fd() const;
182 
183  int refcount() const;
184  bool is_shared() const;
185 
186  static FileHandle cast_static(FileHandle handle);
187  static FileHandle cast_dynamic(FileHandle handle);
189  protected:
190  explicit FileHandle(std::unique_ptr<FileBody> body);
192 
197  explicit FileHandle(FileBody::ptr body);
198 
199  FileBody & body();
200  FileBody const & body() const;
201  static FileBody & body(FileHandle & handle);
202  static FileBody const & body(FileHandle const & handle);
203 
205  void fd(int fd);
206 
207  void * extraPtr() const;
208  void extraPtr(void * ptr);
209 
210  private:
211  FileBody::ptr body_;
213  friend class FileBody;
214  friend class FileHandleAccess;
215  };
216 
225  int retrieve_filehandle(FileHandle handle);
226 
227  //\}
228 
229 }
230 
231 //-/////////////////////////////////////////////////////////////////////////////////////////////////
232 #include "FileHandle.cci"
233 //#include "FileHandle.ct"
234 //#include "FileHandle.cti"
235 #endif
236 
237 
238 // Local Variables:
239 // mode: c++
240 // fill-column: 100
241 // c-file-style: "senf"
242 // indent-tabs-mode: nil
243 // ispell-local-dictionary: "american"
244 // compile-command: "scons -u test"
245 // comment-column: 40
246 // End:
config::time_type clock_type
Basic file handle wrapper.
Definition: FileHandle.hh:102
void terminate()
access FileHandle extra data information
Definition: FileHandle.hh:63
static void * extraPtr(FileHandle const &fh)