28 int fd = ::fileno( file );
33 int flags = ::fcntl( fd, F_GETFL );
40 flags = flags | O_NONBLOCK;
41 else if ( flags & O_NONBLOCK )
42 flags = flags ^ O_NONBLOCK;
44 flags = ::fcntl( fd,F_SETFL,flags );
54 FILE * inputfile = file;
58 int inputfileFd = ::fileno( inputfile );
60 size_t linebuffer_size = 0;
74 int remainingTimeout =
static_cast<int>(
timeout );
86 fd.events = G_IO_IN | G_IO_HUP | G_IO_ERR;
90 g_timer_start( timer );
92 clearerr( inputfile );
94 int retval = g_poll( &fd, 1,
timeout );
97 ERR <<
"select error: " <<
strerror(errno) << std::endl;
104 ssize_t nread = getdelim( &linebuf.
value(), &linebuffer_size, c, inputfile );
106 if ( ::feof( inputfile ) )
112 line += std::string( linebuf, nread );
114 if ( ! ::ferror( inputfile ) || ::feof( inputfile ) ) {
123 remainingTimeout -= g_timer_elapsed( timer,
nullptr );
124 if ( remainingTimeout <= 0 )
BlockingMode setFILEBlocking(FILE *file, bool mode)
Enables or disabled non blocking mode on a file descriptor.
Failed to block or unblock the fd.
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...
FD was non blocking before.
static const timeout_type no_timeout
std::string strerror(int errno_r)
Return string describing the error_r code.
virtual ~TimeoutException() noexcept override
Dtor.