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() ) {
219 const auto read =
eintrSafeCall( ::read, d->_readFds[channel]._readFd, buffer, bufsize );
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 );
void readyRead(uint channel)
void closeReadChannel(uint channel, AsyncDataSource::ChannelCloseReason reason)
void closeWriteChannel(AsyncDataSource::ChannelCloseReason reason)
SocketNotifier::Ptr _writeNotifier
void notifierActivated(const SocketNotifier ¬ify, int evTypes)
Signal< void(uint, AsyncDataSource::ChannelCloseReason)> _sigReadFdClosed
std::vector< ReadChannelDev > _readFds
Signal< void(AsyncDataSource::ChannelCloseReason)> _sigWriteFdClosed
int64_t writeData(const char *data, int64_t count) override
SignalProxy< void(uint, AsyncDataSource::ChannelCloseReason)> sigReadFdClosed()
void readChannelChanged(uint channel) override
bool waitForReadyRead(uint channel, int timeout) override
bool openFds(const std::vector< int > &readFds, int writeFd=-1)
virtual void closeWriteChannel()
int64_t readData(uint channel, char *buffer, int64_t bufsize) override
std::shared_ptr< AsyncDataSource > Ptr
SignalProxy< void(AsyncDataSource::ChannelCloseReason)> sigWriteFdClosed()
int64_t rawBytesAvailable(uint channel) const override
static bool waitForFdEvent(const int fd, int events, int &revents, int &timeout)
int64_t discard(int64_t bytes)
int64_t frontSize() const
Signal< void()> _readyRead
Signal< void()> _sigAllBytesWritten
Signal< void(int64_t)> _sigBytesWritten
std::vector< IOBuffer > _readChannels
Signal< void(uint)> _channelReadyRead
void setReadChannelCount(uint channels)
virtual bool open(const OpenMode mode)
static Ptr create(int socket, int evTypes, bool enable=true)
SignalProxy< void(const SocketNotifier &sock, int evTypes)> sigActivated()
@ FailedToSetMode
Failed to block or unblock the fd.
BlockingMode setFDBlocking(int fd, bool mode)
constexpr std::string_view outOfRangeErrMsg("Channel index out of range")
auto eintrSafeCall(Fun &&function, Args &&... args)
int64_t bytesAvailableOnFD(int fd)
#define ZYPP_IMPL_PRIVATE(Class)