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 = g_poll( &fd, 1, remainingTimeout );
130 if ( errno != EINTR ) {
131 ERR <<
"select error: " << strerror(errno) << std::endl;
138 ssize_t nread = getdelim( &linebuf.
value(), &linebuffer_size, c, inputfile );
140 if ( ::feof( inputfile ) )
146 line += std::string( linebuf, nread );
148 if ( ! ::ferror( inputfile ) || ::feof( inputfile ) ) {
157 remainingTimeout -= g_timer_elapsed( timer,
nullptr ) * 1000;
158 if ( remainingTimeout <= 0 )
Reference counted access to a Tp object calling a custom Dispose function when the last AutoDispose h...
reference value() const
Reference to the Tp object.
virtual ~TimeoutException() noexcept override
Dtor.
bool writeAll(int fd, void *buf, size_t size)
BlockingMode setFILEBlocking(FILE *file, bool mode)
Enables or disabled non blocking mode on a file descriptor.
static const timeout_type no_timeout
std::pair< ReceiveUpToResult, std::string > receiveUpto(FILE *file, char c, timeout_type timeout, bool failOnUnblockError)
@ WasBlocking
FD was blocking before.
@ FailedToSetMode
Failed to block or unblock the fd.
@ WasNonBlocking
FD was non blocking before.
ReadAllResult readAll(int fd, void *buf, size_t size)
BlockingMode setFDBlocking(int fd, bool mode)