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();
157 IODevice::OpenMode mode;
160 for (
const auto readFd : readFds ) {
163 d->_readFds.push_back( {
168 ERR <<
"Failed to set read FD to non blocking" << std::endl;
176 if ( writeFd >= 0 && !error ) {
179 ERR <<
"Failed to set write FD to non blocking" << std::endl;
182 d->_writeFd = writeFd;
191 d->_writeNotifier.reset();
206 d->_writeBuffer.append( data, count );
207 d->_writeNotifier->setEnabled(
true );
215 if ( channel >= d->_readFds.size() ) {
222 #if EAGAIN != EWOULDBLOCK 239 if ( channel >= d->_readFds.size() ) {
252 if ( channel >= d->_readFds.size() ) {
261 for( uint i = 0; i < d->_readFds.size(); ++i ) {
262 auto &readChan = d->_readFds[i];
263 readChan._readNotifier.reset();
264 if ( readChan._readFd >= 0)
269 d->_writeNotifier.reset();
270 d->_writeBuffer.clear();
271 if ( d->_writeFd >= 0 ) {
290 d->_writeNotifier.reset();
291 d->_writeBuffer.clear();
293 if ( d->_writeFd >= 0 ) {
305 if ( channel >= d->_readFds.size() ) {
311 auto rrConn =
AutoDisconnect( d->_channelReadyRead.connect([&]( uint activated ){
312 gotRR = ( channel == activated );
316 auto &channelRef = d->_readFds[ channel ];
321 d->notifierActivated( *channelRef._readNotifier, rEvents );
337 while (
canWrite() && d->_writeBuffer.frontSize() ) {
351 return d_func()->_sigWriteFdClosed;
356 return d_func()->_sigReadFdClosed;
362 if ( !d->_readChannels.size() )
364 return readFdOpen( d_func()->_currentReadChannel );
370 if ( channel >= d->_readFds.size() ) {
374 auto &channelRef = d->_readFds[ channel ];
375 return ( channelRef._readNotifier && channelRef._readFd >= 0 );
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)
std::map< std::string, std::string > read(const Pathname &_path)
Read sysconfig file path_r and return (key,valye) pairs.
Signal< void()> _sigAllBytesWritten
SignalProxy< void(uint, AsyncDataSource::ChannelCloseReason)> sigReadFdClosed()
std::vector< ReadChannelDev > _readFds
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, 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
Signal< void()> _readyRead
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)
bool openFds(const std::vector< int > &readFds, int writeFd=-1)
SignalProxy< void(const SocketNotifier &sock, int evTypes)> sigActivated()
Signal< void(uint)> _channelReadyRead
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