| Disk ARchive 2.8.3 Full featured and portable backup and archiving tool

Loading...
Searching...
No Matches
src/libdar/tuyau.hpp
Go to the documentation of this file.
1/*********************************************************************/
2// dar - disk archive - a backup/restoration program
3// Copyright (C) 2002-2026 Denis Corbin
4//
5// This program is free software; you can redistribute it and/or
6// modify it under the terms of the GNU General Public License
7// as published by the Free Software Foundation; either version 2
8// of the License, or (at your option) any later version.
9//
10// This program is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with this program; if not, write to the Free Software
17// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18//
19// to contact the author, see the AUTHOR file
20/*********************************************************************/
21
30
31#ifndef TUYAU_HPP
32#define TUYAU_HPP
33
34#include "../my_config.h"
35#include "infinint.hpp"
36#include "generic_file.hpp"
37#include "thread_cancellation.hpp"
38#include "mem_ui.hpp"
39
40 namespace libdar
41{
42
45
47
48 class tuyau : public generic_file, public thread_cancellation, protected mem_ui
49 {
50 public:
51 tuyau(const std::shared_ptr<user_interaction> & dialog,
52 int fd
53 );
54 tuyau(const std::shared_ptr<user_interaction> & dialog,
55 int fd,
56 gf_mode mode
57 );
58 tuyau(const std::shared_ptr<user_interaction> & dialog,
59 const std::string &filename,
60 gf_mode mode
61 );
62
63 tuyau(const std::shared_ptr<user_interaction> & dialog);
64 tuyau(const tuyau & ref) = default;
65 tuyau(tuyau && ref) noexcept = default;
66 tuyau & operator = (const tuyau & ref) = default;
67 tuyau & operator = (tuyau && ref) noexcept = default;
68 ~tuyau();
69
72 int get_read_fd() const;
73
75
79 void close_read_fd();
80
82 void do_not_close_read_fd();
83
84 // inherited from generic_file
85 virtual bool skippable(skippability direction, const infinint & amount) override;
86 virtual bool skip(const infinint & pos) override;
87 virtual bool skip_to_eof() override;
88 virtual bool skip_relative(signed int x) override;
89 virtual bool truncatable(const infinint & pos) const override { return pos >= position; };
90 virtual infinint get_position() const override { return position; };
91
92 bool has_next_to_read();
93
94 protected:
95 virtual void inherited_read_ahead(const infinint & amount) override {}; // relying on the operating system
96 virtual U_I inherited_read(char *a, U_I size) override;
97 virtual void inherited_write(const char *a, U_I size) override;
98 virtual void inherited_truncate(const infinint & pos) override { if(pos < position) throw SRC_BUG; };
99 virtual void inherited_sync_write() override {};
100 virtual void inherited_flush_read() override {};
101 virtual void inherited_terminate() override;
102
103 private:
104 enum
105 {
106 pipe_fd,
107 pipe_path,
108 pipe_both
109 } pipe_mode;
110 infinint position;
111 int filedesc;
112 int other_end_fd;
113 std::string chemin;
114 bool has_one_to_read;
115 char next_to_read;
116
117 void ouverture();
118
120
123 bool read_and_drop(infinint byte);
124
126 bool read_to_eof();
127 };
128
130
131} // end of namespace
132
133#endif
libdar::generic_file
this is the interface class from which all other data transfer classes inherit
Definition dar64-2.8.3-win64/include/dar/generic_file.hpp:77
libdar::infinint
the arbitrary large positive integer class
Definition dar64-2.8.3-win64/include/dar/real_infinint.hpp:62
libdar::mem_ui
class mem_ui to keep a copy of a user_interaction object
Definition dar64-2.8.3-win64/include/dar/mem_ui.hpp:55
libdar::thread_cancellation
class to be used as parent to provide checkpoints to inherited classes
Definition dar64-2.8.3-win64/include/dar/thread_cancellation.hpp:69
libdar::tuyau
pipe implementation under the generic_file interface.
Definition dar64-2.8.3-win64/include/dar/tuyau.hpp:49
libdar::tuyau::pipe_mode
enum libdar::tuyau::@221274302035021350145006121145025317235315017354 pipe_mode
defines how the object's status (which possible values defined by the anonymous enum above)
libdar::tuyau::read_to_eof
bool read_to_eof()
skip to eof by reading data
libdar::tuyau::chemin
std::string chemin
in pipe_path mode only, this holds the named pipe to be open
Definition dar64-2.8.3-win64/include/dar/tuyau.hpp:113
libdar::tuyau::inherited_terminate
virtual void inherited_terminate() override
destructor-like call, except that it is allowed to throw exceptions
libdar::tuyau::other_end_fd
int other_end_fd
in pipe_both mode, this holds the reading side of the anonymous pipe
Definition dar64-2.8.3-win64/include/dar/tuyau.hpp:112
libdar::tuyau::tuyau
tuyau(const std::shared_ptr< user_interaction > &dialog, int fd)
libdar::tuyau::read_and_drop
bool read_and_drop(infinint byte)
skip forward by reading data
libdar::tuyau::skippable
virtual bool skippable(skippability direction, const infinint &amount) override
whether the implementation is able to skip
libdar::tuyau::get_position
virtual infinint get_position() const override
get the current read/write position
Definition src/libdar/tuyau.hpp:90
libdar::tuyau::inherited_read_ahead
virtual void inherited_read_ahead(const infinint &amount) override
tells the object that several calls to read() will follow to probably obtain at least the given amoun...
Definition src/libdar/tuyau.hpp:95
libdar::tuyau::skip_to_eof
virtual bool skip_to_eof() override
skip to the end of file
libdar::tuyau::do_not_close_read_fd
void do_not_close_read_fd()
ask to not close the read descriptor upon object destruction (the fd survives the object)
libdar::tuyau::inherited_read
virtual U_I inherited_read(char *a, U_I size) override
implementation of read() operation
libdar::tuyau::skip
virtual bool skip(const infinint &pos) override
skip at the absolute position
libdar::tuyau::inherited_write
virtual void inherited_write(const char *a, U_I size) override
implementation of the write() operation
libdar::tuyau::close_read_fd
void close_read_fd()
closes the read fd of the anonymous pipe (this is to be used by a writer)
libdar::tuyau::get_read_fd
int get_read_fd() const
libdar::tuyau::tuyau
tuyau(const std::shared_ptr< user_interaction > &dialog)
creates a anonymous pipe and bind itself to the writing end. The reading end can be obtained by get_r...
libdar::tuyau::position
infinint position
recorded position in the stream
Definition dar64-2.8.3-win64/include/dar/tuyau.hpp:110
libdar::tuyau::tuyau
tuyau(const std::shared_ptr< user_interaction > &dialog, const std::string &filename, gf_mode mode)
libdar::tuyau::inherited_flush_read
virtual void inherited_flush_read() override
reset internal engine, flush caches in order to read the data at current position
Definition src/libdar/tuyau.hpp:100
libdar::tuyau::truncatable
virtual bool truncatable(const infinint &pos) const override
whether the implementation is able to truncate to the given position
Definition src/libdar/tuyau.hpp:89
libdar::tuyau::filedesc
int filedesc
file descriptors of the pipe
Definition dar64-2.8.3-win64/include/dar/tuyau.hpp:111
libdar::tuyau::next_to_read
char next_to_read
when has_one_to_read is true, contains the next to read byte
Definition dar64-2.8.3-win64/include/dar/tuyau.hpp:115
libdar::tuyau::has_one_to_read
bool has_one_to_read
if true, the next char to read is placed in "next_to_read"
Definition dar64-2.8.3-win64/include/dar/tuyau.hpp:114
libdar::tuyau::tuyau
tuyau(const std::shared_ptr< user_interaction > &dialog, int fd, gf_mode mode)
libdar::tuyau::inherited_sync_write
virtual void inherited_sync_write() override
write down any pending data
Definition src/libdar/tuyau.hpp:99
libdar::tuyau::inherited_truncate
virtual void inherited_truncate(const infinint &pos) override
truncate file at the give offset
Definition src/libdar/tuyau.hpp:98
libdar::tuyau::pipe_path
@ pipe_path
holds a filename to be openned (named pipe)
Definition dar64-2.8.3-win64/include/dar/tuyau.hpp:107
libdar::tuyau::pipe_both
@ pipe_both
holds a pair of file descriptors
Definition dar64-2.8.3-win64/include/dar/tuyau.hpp:108
libdar::tuyau::pipe_fd
@ pipe_fd
holds a single file descriptor for the pipe
Definition dar64-2.8.3-win64/include/dar/tuyau.hpp:106
libdar::gf_mode
gf_mode
generic_file openning modes
Definition dar64-2.8.3-win64/include/dar/gf_mode.hpp:44
my_config.h
include macro defined by the configure script and some specific additional ones
libdar
libdar namespace encapsulate all libdar symbols
Definition dar64-2.8.3-win64/include/dar/archive.hpp:47
generic_file.hpp
class generic_file is defined here as well as class fichier
infinint.hpp
switch module to limitint (32 ou 64 bits integers) or infinint
mem_ui.hpp
class mem_ui definition. This class is to be used as parent class to handle user_interaction object m...
thread_cancellation.hpp
to be able to cancel libdar operation while running in a given thread.