18 #include <zypp-core/AutoDispose.h> 19 #include <zypp-core/base/IOTools.h> 20 #include <zypp-core/base/LogTools.h> 21 #include <zypp-core/zyppng/base/private/linuxhelpers_p.h> 36 int flags = ::fcntl( fd, F_GETFL );
43 flags = flags | O_NONBLOCK;
44 else if ( flags & O_NONBLOCK )
45 flags = flags ^ O_NONBLOCK;
47 flags = ::fcntl( fd,F_SETFL,flags );
57 char *tmpBuf = (
char *) buf;
60 while ( written < size ) {
61 const auto res = zyppng::eintrSafeCall( ::
write, fd, tmpBuf+written, size-written );
71 char *tmpBuf = (
char *)buf;
73 while (
read != size ) {
74 const auto r = zyppng::eintrSafeCall( ::
read, fd, tmpBuf+
read, size -
read );
87 FILE * inputfile = file;
91 int inputfileFd = ::fileno( inputfile );
93 size_t linebuffer_size = 0;
107 int remainingTimeout =
static_cast<int>( timeout );
119 fd.events = G_IO_IN | G_IO_HUP | G_IO_ERR;
123 g_timer_start( timer );
125 clearerr( inputfile );
127 int retval = zyppng::eintrSafeCall( g_poll, &fd, 1, remainingTimeout );
130 ERR <<
"select error: " << zyppng::strerr_cxx() << std::endl;
136 ssize_t nread = zyppng::eintrSafeCallEx( ::getdelim, [&](){ clearerr( inputfile ); }, &linebuf.
value(), &linebuffer_size, c, inputfile );
138 if ( ::feof( inputfile ) ) {
141 if ( errno != EAGAIN && ( ::ferror( inputfile ) || errno != 0 ) ) {
142 if ( errno )
ERR <<
"getdelim error: " << zyppng::strerr_cxx() << std::endl;
143 else ERR <<
"Unknown getdelim error." << std::endl;
150 line += std::string( linebuf, nread );
152 if ( ! ::ferror( inputfile ) || ::feof( inputfile ) ) {
161 remainingTimeout -= g_timer_elapsed( timer,
nullptr ) * 1000;
162 if ( remainingTimeout <= 0 )
178 std::vector<char> data( count + 1 ,
'\0' );
181 while ((l = pread( fileno( fd ), data.data(), count, offset ) ) == -1 && errno == EINTR)
std::map< std::string, std::string > read(const Pathname &_path)
Read sysconfig file path_r and return (key,valye) pairs.
BlockingMode setFILEBlocking(FILE *file, bool mode)
Enables or disabled non blocking mode on a file descriptor.
bool write(const Pathname &path_r, const std::string &key_r, const std::string &val_r, const std::string &newcomment_r)
Add or change a value in sysconfig file path_r.
Failed to block or unblock the fd.
std::vector< char > peek_data_fd(FILE *fd, off_t offset, size_t count)
bool writeAll(int fd, void *buf, size_t size)
std::pair< ReceiveUpToResult, std::string > receiveUpto(FILE *file, char c, timeout_type timeout, bool failOnUnblockError)
reference value() const
Reference to the Tp object.
Reference counted access to a Tp object calling a custom Dispose function when the last AutoDispose h...
static constexpr timeout_type no_timeout
FD was non blocking before.
std::string strerror(int errno_r)
Return string describing the error_r code.
virtual ~TimeoutException() noexcept override
Dtor.
ReadAllResult readAll(int fd, void *buf, size_t size)
BlockingMode setFDBlocking(int fd, bool mode)