/*-------------------------------------------------------------------------- Copyright 1999,2000, Dan Kegel http://www.kegel.com/ See the file COPYING (Also freely licensed to Disappearing, Inc. under a separate license which allows them to do absolutely anything they want with it, without regard to the GPL.) This module is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This module is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA --------------------------------------------------------------------------*/ #include "dprint.h" #include "Poller.h" #include #include #include #include int Poller::init() { m_wakeup_pipe[0] = -1; m_wakeup_pipe[1] = -1; return 0; } int Poller::initWakeUpPipe() { // Create the pipe used by wakeUp int err; if (pipe(m_wakeup_pipe)) { err = errno; LOG_ERROR(("init: pipe() failed, errno %d\n", err)); return err; } // Set the pipe to be nonblocking. The pipe carries hints only; // we never want to sleep if we can't read or write it. if (fcntl(m_wakeup_pipe[0], F_SETFL, O_NONBLOCK) || fcntl(m_wakeup_pipe[1], F_SETFL, O_NONBLOCK)) { err = errno; LOG_ERROR(("init: fcntl() failed, errno %d\n", err)); return err; } // Wake this Poller up whenever a byte gets written to the pipe by wakeUp(). add(m_wakeup_pipe[0], &m_pipe_client, POLLIN); return 0; } void Poller::shutdown() { if (m_wakeup_pipe[0] != -1) { close(m_wakeup_pipe[0]); m_wakeup_pipe[0] = -1; close(m_wakeup_pipe[1]); m_wakeup_pipe[1] = -1; } }