4 #include <zypp-core/zyppng/base/AutoDisconnect> 5 #include <zypp-core/zyppng/base/EventDispatcher> 14 DBG <<
"Closing due to error when polling" << std::endl;
22 [ ¬ify ](
const auto &dev ){
return ( dev._readNotifier.get() == ¬ify ); } );
34 auto bytesToRead = z_func()->rawBytesAvailable( channel );
35 if ( bytesToRead == 0 ) {
41 char *buf = _readBuf.reserve( bytesToRead );
42 const auto bytesRead = z_func()->readData( channel, buf, bytesToRead );
44 if ( bytesRead <= 0 ) {
45 _readBuf.chop( bytesToRead );
65 if ( bytesToRead > bytesRead )
66 _readBuf.chop( bytesToRead-bytesRead );
86 if ( written == -1 ) {
92 #if EAGAIN != EWOULDBLOCK 128 bool sig = readFd._readFd >= 0;
129 readFd._readNotifier.reset();
132 z_func()->finishReadChannel( channel );
159 IODevice::OpenMode mode;
162 for (
const auto readFd : readFds ) {
165 d->_readFds.push_back( {
170 ERR <<
"Failed to set read FD to non blocking" << std::endl;
178 if ( writeFd >= 0 && !error ) {
181 ERR <<
"Failed to set write FD to non blocking" << std::endl;
184 d->_writeFd = writeFd;
193 d->_writeNotifier.reset();
208 d->_writeBuffer.append( data, count );
209 d->_writeNotifier->setEnabled(
true );
217 if ( channel >= d->_readFds.size() ) {
224 #if EAGAIN != EWOULDBLOCK 241 if ( channel >= d->_readFds.size() ) {
254 if ( channel >= d->_readFds.size() ) {
263 for( uint i = 0; i < d->_readFds.size(); ++i ) {
264 auto &readChan = d->_readFds[i];
265 readChan._readNotifier.reset();
266 if ( readChan._readFd >= 0) {
267 finishReadChannel(i);
273 d->_writeNotifier.reset();
274 d->_writeBuffer.clear();
275 if ( d->_writeFd >= 0 ) {
294 d->_writeNotifier.reset();
295 d->_writeBuffer.clear();
297 if ( d->_writeFd >= 0 ) {
309 if ( channel >= d->_readFds.size() ) {
315 auto rrConn =
AutoDisconnect( d->_channelReadyRead.connect([&]( uint activated ){
316 gotRR = ( channel == activated );
320 auto &channelRef = d->_readFds[ channel ];
325 d->notifierActivated( *channelRef._readNotifier, rEvents );
341 while (
canWrite() && d->_writeBuffer.frontSize() ) {
355 return d_func()->_sigWriteFdClosed;
360 return d_func()->_sigReadFdClosed;
366 if ( !d->_readChannels.size() )
368 return readFdOpen( d_func()->_currentReadChannel );
374 if ( channel >= d->_readFds.size() ) {
378 auto &channelRef = d->_readFds[ channel ];
379 return ( channelRef._readNotifier && channelRef._readFd >= 0 );
384 return d_func()->_writeBuffer.size();
SignalProxy< void(AsyncDataSource::ChannelCloseReason)> sigWriteFdClosed()
virtual bool open(const OpenMode mode)
void notifierActivated(const SocketNotifier ¬ify, int evTypes)
void setReadChannelCount(uint channels)
Signal< void(AsyncDataSource::ChannelCloseReason)> _sigWriteFdClosed
static Ptr create(int socket, int evTypes, bool enable=true)
void closeReadChannel(uint channel, AsyncDataSource::ChannelCloseReason reason)
Signal< void()> _sigAllBytesWritten
SignalProxy< void(uint, AsyncDataSource::ChannelCloseReason)> sigReadFdClosed()
std::vector< ReadChannelDev > _readFds
Signal< void(uint, AsyncDataSource::ChannelCloseReason)> _sigReadFdClosed
void closeWriteChannel(AsyncDataSource::ChannelCloseReason reason)
static bool waitForFdEvent(const int fd, int events, int &revents, int &timeout)
int64_t rawBytesAvailable(uint channel) const override
int64_t writeData(const char *data, int64_t count) override
Failed to block or unblock the fd.
void readChannelChanged(uint channel) override
SocketNotifier::Ptr _writeNotifier
int64_t discard(int64_t bytes)
int64_t frontSize() const
void readyRead(uint channel)
constexpr std::string_view outOfRangeErrMsg("Channel index out of range")
virtual void closeWriteChannel()
auto eintrSafeCall(Fun &&function, Args &&... args)
int64_t readData(uint channel, char *buffer, int64_t bufsize) override
ZYPP_IMPL_PRIVATE(UnixSignalSource)
int64_t bytesPending() const override
bool openFds(const std::vector< int > &readFds, int writeFd=-1)
std::map< std::string, std::string > read(const Pathname &_path)
Read sysconfig file path_r and return (key,valye) pairs.
SignalProxy< void(const SocketNotifier &sock, int evTypes)> sigActivated()
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.
Signal< void(uint) > _channelReadyRead
Signal< void() > _readyRead
std::vector< IOBuffer > _readChannels
Signal< void(int64_t)> _sigBytesWritten
int64_t bytesAvailableOnFD(int fd)
std::shared_ptr< AsyncDataSource > Ptr
BlockingMode setFDBlocking(int fd, bool mode)
bool waitForReadyRead(uint channel, int timeout) override