10 #include "wvstreamsdaemon.h"
16 void WvStreamsDaemon::init(WvDaemonCallback cb)
18 do_full_close =
false;
21 signal(SIGPIPE, SIG_IGN);
25 void WvStreamsDaemon::do_start()
32 void WvStreamsDaemon::do_run()
34 if (streams.isempty())
36 log(WvLog::Error,
"No streams; exiting\n");
43 WvIStreamList::globallist.
runonce();
47 void WvStreamsDaemon::do_stop()
49 WvIStreamList::Iter stream(streams);
50 for (stream.rewind(); stream.next(); )
51 WvIStreamList::globallist.unlink(stream.ptr());
54 WvIStreamList::globallist.zap();
60 bool autofree,
const char *
id)
62 streams.append(istream,
false,
id);
65 WvIStreamList::globallist.append(istream, autofree,
id);
78 bool autofree,
const char *
id)
86 void WvStreamsDaemon::restart_close_cb(
IWvStream *s,
const char *
id)
91 log(WvLog::Error,
"%s is closed (%s); restarting\n",
92 id ?
id :
"Stream", err);
97 void WvStreamsDaemon::die_close_cb(
IWvStream *s,
const char *
id)
102 log(WvLog::Error,
"%s is closed (%s); dying\n",
103 id ?
id :
"Stream", err);
virtual IWvStreamCallback setclosecallback(IWvStreamCallback _callfunc)=0
Sets a callback to be invoked on close().
bool should_run() const
Whether the daemon should continue runnning.
WvLog log
The daemon's log mechanism.
void die(int status=0)
Force the daemon to exit as soon as the run callback exits.
bool want_to_die() const
Whether the daemon will quit when the run callback exits.
void restart()
Force the daemon to restart as soon as the run callback exits.
virtual int geterr() const
If isok() is false, return the system error number corresponding to the error, -1 for a special error...
void runonce(time_t msec_timeout=-1)
Exactly the same as: if (select(timeout)) callback();.
void setcallback(WvDaemonCallback cb)
Change the callback function and userdata.
void add_restart_stream(IWvStream *istream, bool auto_free, const char *id)
Add a stream to the daemon; the daemon will restart, re-populating the initial streams using the call...
void add_die_stream(IWvStream *istream, bool auto_free, const char *id)
Add a stream to the daemon; if the stream goes !isok() the daemon will exit.
void add_stream(IWvStream *istream, bool auto_free, const char *id)
Add a stream to the daemon; don't do anything if it goes !isok().
WvString is an implementation of a simple and efficient printable-string class.