CernVM-FS  2.12.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
sink_file.h
Go to the documentation of this file.
1 
5 #ifndef CVMFS_NETWORK_SINK_FILE_H_
6 #define CVMFS_NETWORK_SINK_FILE_H_
7 
8 #include <cerrno>
9 #include <cstdio>
10 #include <string>
11 
12 #include "sink.h"
13 #include "util/posix.h"
14 
15 namespace cvmfs {
16 
25 class FileSink : public Sink {
26  public:
27  explicit FileSink(FILE *destination_file) : Sink(false),
28  file_(destination_file) { }
29  FileSink(FILE *destination_file, bool is_owner) : Sink(is_owner),
30  file_(destination_file) { }
31 
32  virtual ~FileSink() { if (is_owner_ && file_) { (void) fclose(file_); } }
33 
40  virtual int64_t Write(const void *buf, uint64_t sz);
41 
48  virtual int Reset();
49 
50  virtual int Purge();
51 
55  virtual bool IsValid() {
56  return file_ != NULL;
57  }
58 
64  virtual int Flush() {
65  return fflush(file_) == 0 ? 0 : -errno;
66  }
67 
84  virtual bool Reserve(size_t /*size*/) {
85  return true;
86  }
87 
94  virtual bool RequiresReserve() {
95  return false;
96  }
97 
101  virtual std::string Describe();
102 
107  void Adopt(FILE *file, bool is_owner = true);
108 
109  FILE* file() { return file_; }
110 
111 
112 
113  private:
114  FILE *file_;
115 };
116 
117 } // namespace cvmfs
118 
119 #endif // CVMFS_NETWORK_SINK_FILE_H_
FileSink(FILE *destination_file, bool is_owner)
Definition: sink_file.h:29
virtual int Purge()
Definition: sink_file.cc:53
virtual std::string Describe()
Definition: sink_file.cc:70
virtual bool IsValid()
Definition: sink_file.h:55
virtual bool RequiresReserve()
Definition: sink_file.h:94
virtual int Flush()
Definition: sink_file.h:64
void Adopt(FILE *file, bool is_owner=true)
Definition: sink_file.cc:75
FILE * file()
Definition: sink_file.h:109
virtual int64_t Write(const void *buf, uint64_t sz)
Definition: sink_file.cc:19
virtual bool Reserve(size_t)
Definition: sink_file.h:84
virtual int Reset()
Definition: sink_file.cc:38
FileSink(FILE *destination_file)
Definition: sink_file.h:27
bool is_owner_
Definition: sink.h:99
virtual ~FileSink()
Definition: sink_file.h:32