libzypp  17.28.8
IOTools.h
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
12 #ifndef ZYPP_BASE_IOTOOLS_H
13 #define ZYPP_BASE_IOTOOLS_H
14 
15 #include <stdio.h>
16 #include <utility>
17 #include <string>
18 #include <zypp-core/base/Exception.h>
19 
20 namespace zypp::io {
21 
22  enum class BlockingMode{
23  FailedToSetMode = -1,
24  WasBlocking,
26  };
27 
32  BlockingMode setFILEBlocking ( FILE *file, bool mode = true );
33  BlockingMode setFDBlocking ( int fd, bool mode = true );
34 
38  bool writeAll ( int fd, void *buf, size_t size );
39 
43  enum class ReadAllResult {
44  Error,
45  Eof,
46  Ok
47  };
48  ReadAllResult readAll ( int fd, void *buf, size_t size );
49 
50  class TimeoutException : public Exception
51  {
52  public:
56  TimeoutException() : Exception( "Timeout Exception" )
57  {}
61  TimeoutException( const std::string & msg_r )
62  : Exception( msg_r )
63  {}
64 
66  virtual ~TimeoutException() noexcept override;
67  };
68 
74  };
75 
76  using timeout_type = size_t;
77  static const timeout_type no_timeout = static_cast<timeout_type>(-1);
78 
85  std::pair<ReceiveUpToResult, std::string> receiveUpto( FILE * file, char c, timeout_type timeout, bool failOnUnblockError = true );
86 }
87 
88 #endif
89 
Base class for Exception.
Definition: Exception.h:146
TimeoutException(const std::string &msg_r)
Ctor taking message.
Definition: IOTools.h:61
virtual ~TimeoutException() noexcept override
Dtor.
Definition: IOTools.cc:164
TimeoutException()
Ctor taking message.
Definition: IOTools.h:56
ReadAllResult
Definition: IOTools.h:43
bool writeAll(int fd, void *buf, size_t size)
Definition: IOTools.cc:55
BlockingMode setFILEBlocking(FILE *file, bool mode)
Enables or disabled non blocking mode on a file descriptor.
Definition: IOTools.cc:25
static const timeout_type no_timeout
Definition: IOTools.h:77
std::pair< ReceiveUpToResult, std::string > receiveUpto(FILE *file, char c, timeout_type timeout, bool failOnUnblockError)
Definition: IOTools.cc:85
BlockingMode
Definition: IOTools.h:22
@ WasBlocking
FD was blocking before.
@ FailedToSetMode
Failed to block or unblock the fd.
@ WasNonBlocking
FD was non blocking before.
ReceiveUpToResult
Definition: IOTools.h:69
@ Timeout
Definition: IOTools.h:71
@ Success
Definition: IOTools.h:70
@ Error
Definition: IOTools.h:73
@ EndOfFile
Definition: IOTools.h:72
ReadAllResult readAll(int fd, void *buf, size_t size)
Definition: IOTools.cc:69
BlockingMode setFDBlocking(int fd, bool mode)
Definition: IOTools.cc:31
size_t timeout_type
Definition: IOTools.h:76