// If the queue is empty, we can try to write the packet out now rather than queueing it.
// If the write is unsuccessful or partial, we queue the remainder.
if (was_empty) {
- int wr = write(iob.fd, pkt, size);
+ int wr = write(iob.getWatchedFd(), pkt, size);
if (wr == -1) {
if (errno == EPIPE) {
return false;
if (was_empty) {
outpkt_index = 0;
// We can try sending the packet immediately:
- int wr = write(iob.fd, pkt.data(), pkt.size());
+ int wr = write(iob.getWatchedFd(), pkt.data(), pkt.size());
if (wr == -1) {
if (errno == EPIPE) {
return false;
bool ControlConn::dataReady() noexcept
{
- int fd = iob.fd;
+ int fd = iob.getWatchedFd();
int r = rbuf.fill(fd);
if (oom_close) {
// Send oom response
char oomBuf[] = { DINIT_RP_OOM };
- write(iob.fd, oomBuf, 1);
+ write(iob.getWatchedFd(), oomBuf, 1);
}
return true;
}
vector<char> & pkt = outbuf.front();
char *data = pkt.data();
- int written = write(iob.fd, data + outpkt_index, pkt.size() - outpkt_index);
+ int written = write(iob.getWatchedFd(), data + outpkt_index, pkt.size() - outpkt_index);
if (written == -1) {
if (errno == EPIPE) {
// read end closed
ControlConn::~ControlConn() noexcept
{
- close(iob.fd);
+ close(iob.getWatchedFd());
iob.deregister(*loop);
// Clear service listeners
}
public:
- int fd; // TODO this is already stored, find a better way to access it.
EventLoop_t * eventLoop;
void setWatches(int flags)
void registerWith(EventLoop_t &loop, int fd, int flags)
{
- this->fd = fd;
this->eventLoop = &loop;
BidiFdWatcher<EventLoop_t>::addWatch(loop, fd, flags);
}
control_socket_cb(&loop, fd);
return Rearm::REARM;
}
-
- public:
- // TODO the fd is already stored, must we really store it again...
- int fd;
-
- void addWatch(EventLoop_t &loop, int fd, int flags)
- {
- this->fd = fd;
- EventLoop_t::FdWatcher::addWatch(loop, fd, flags);
- }
};
ControlSocketWatcher control_socket_io;
static void close_control_socket() noexcept
{
if (control_socket_open) {
- int fd = control_socket_io.fd;
+ int fd = control_socket_io.getWatchedFd();
control_socket_io.deregister(eventLoop);
close(fd);