8#include "wvistreamlist.h"
9#include "wvstringlist.h"
10#include "wvstreamsdebugger.h"
20#ifdef HAVE_VALGRIND_MEMCHECK_H
21#include <valgrind/memcheck.h>
23#define RUNNING_ON_VALGRIND false
30# define TRACE(x, y...) fprintf(stderr, x, ## y)
33# define TRACE(x, y...)
42WvIStreamList::WvIStreamList():
43 in_select(false), dead_stream(false)
45 readcb = writecb = exceptcb = 0;
47 if (
this == &globallist)
53 set_wsname(
"globallist");
54 add_debugger_commands();
59WvIStreamList::~WvIStreamList()
75 guard_bool(_guard_bool)
92 bool already_sure =
false;
101 IWvStream *old_in_stream = WvCrashInfo::in_stream;
102 const char *old_in_stream_id = WvCrashInfo::in_stream_id;
103 WvCrashInfo::InStreamState old_in_stream_state = WvCrashInfo::in_stream_state;
104 WvCrashInfo::in_stream_state = WvCrashInfo::PRE_SELECT;
107 for (i.rewind(); i.next(); )
110#if I_ENJOY_FORMATTING_STRINGS
111 WvCrashWill will(
"doing pre_select for \"%s\" (%s)\n%s",
112 i.link->id,
ptr2str(&s), wvcrash_read_will());
114 WvCrashInfo::in_stream = &s;
115 WvCrashInfo::in_stream_id = i.link->id;
123 TRACE(
"after pre_select(%s): msec_timeout is %ld\n",
124 i.link->id, (
long)si.msec_timeout);
127 WvCrashInfo::in_stream = old_in_stream;
128 WvCrashInfo::in_stream_id = old_in_stream_id;
129 WvCrashInfo::in_stream_state = old_in_stream_state;
131 if (alarmleft >= 0 && (alarmleft < si.msec_timeout || si.msec_timeout < 0))
132 si.msec_timeout = alarmleft;
144 bool already_sure =
false;
151 IWvStream *old_in_stream = WvCrashInfo::in_stream;
152 const char *old_in_stream_id = WvCrashInfo::in_stream_id;
153 WvCrashInfo::InStreamState old_in_stream_state = WvCrashInfo::in_stream_state;
154 WvCrashInfo::in_stream_state = WvCrashInfo::POST_SELECT;
157 for (i.rewind(); i.cur() && i.next(); )
160#if I_ENJOY_FORMATTING_STRINGS
161 WvCrashWill will(
"doing post_select for \"%s\" (%s)\n%s",
162 i.link->id,
ptr2str(&s), wvcrash_read_will());
164 WvCrashInfo::in_stream = &s;
165 WvCrashInfo::in_stream_id = i.link->id;
169 if (s.post_select(si))
171 TRACE(
"post_select(%s) was true\n", i.link->id);
172 sure_thing.unlink(&s);
174 sure_thing.append(&s,
true, i.link->id);
178 TRACE(
"post_select(%s) was false\n", i.link->id);
179 WvIStreamListBase::Iter j(sure_thing);
180 WvLink* link = j.find(&s);
182 wvassert(!link,
"stream \"%s\" (%s) was ready in "
183 "pre_select, but not in post_select",
184 link->id,
ptr2str(link->data));
195 WvCrashInfo::in_stream = old_in_stream;
196 WvCrashInfo::in_stream_id = old_in_stream_id;
197 WvCrashInfo::in_stream_state = old_in_stream_state;
200 return already_sure || !sure_thing.isempty();
207 static int level = 0;
213 TRACE(
"\n%*sList@%p: (%d sure) ", level,
"",
this, sure_thing.count());
215 IWvStream *old_in_stream = WvCrashInfo::in_stream;
216 const char *old_in_stream_id = WvCrashInfo::in_stream_id;
217 WvCrashInfo::InStreamState old_in_stream_state = WvCrashInfo::in_stream_state;
218 WvCrashInfo::in_stream_state = WvCrashInfo::EXECUTE;
220 WvIStreamListBase::Iter i(sure_thing);
221 for (i.rewind(); i.next(); )
224 WvIStreamListBase::Iter x(*
this);
226 TRACE(
"Yikes! %p in sure_thing, but not in main list!\n",
234 TRACE(
"[%p:%s]", &s,
id);
239 if (!RUNNING_ON_VALGRIND)
241 WvString strace_node(
"%s: %s", s.wstype(), s.wsname());
242 ::write(-1, strace_node, strace_node.len());
245#if I_ENJOY_FORMATTING_STRINGS
247 id ?
id :
"unknown stream",
248 wvcrash_read_will());
250 WvCrashInfo::in_stream = &s;
251 WvCrashInfo::in_stream_id = id;
261 WvCrashInfo::in_stream = old_in_stream;
262 WvCrashInfo::in_stream_id = old_in_stream_id;
263 WvCrashInfo::in_stream_state = old_in_stream_state;
268 TRACE(
"[DONE %p]\n",
this);
272void WvIStreamList::onfork(pid_t p)
277 globallist.zap(
false);
283void WvIStreamList::add_debugger_commands()
285 WvStreamsDebugger::add_command(
"globallist", 0, debugger_globallist_run_cb, 0);
291 WvStreamsDebugger::ResultCallback result_cb,
void *)
293 debugger_streams_display_header(cmd, result_cb);
294 WvIStreamList::Iter i(globallist);
295 for (i.rewind(); i.next(); )
296 debugger_streams_maybe_display_one_stream(
static_cast<WvStream *
>(i.ptr()),
297 cmd, args, result_cb);
299 return WvString::null;
virtual unsigned int addRef()=0
Indicate you are using this object.
virtual unsigned int release()=0
Indicate that you are finished using this object.
virtual bool isok() const =0
By default, returns true if geterr() == 0.
A WvFastString acts exactly like a WvString, but can take (const char *) strings without needing to a...
WvStreamList holds a list of WvStream objects – and its select() and callback() functions know how to...
virtual void pre_select(SelectInfo &si)
pre_select() sets up for eventually calling select().
virtual bool post_select(SelectInfo &si)
post_select() is called after select(), and returns true if this object is now ready.
virtual bool isok() const
return true if the stream is actually usable right now
virtual void execute()
The callback() function calls execute(), and then calls the user- specified callback if one is define...
WvLink is one element of a WvList<T>.
Unified support for streams, that is, sequences of bytes that may or may not be ready for read/write ...
virtual void execute()
The callback() function calls execute(), and then calls the user- specified callback if one is define...
virtual bool isok() const
return true if the stream is actually usable right now
virtual size_t write(const void *buf, size_t count)
Write data to the stream.
virtual void close()
Close the stream if it is open; isok() becomes false from now on.
time_t alarm_remaining()
return the number of milliseconds remaining before the alarm will go off; -1 means no alarm is set (i...
This is a WvList of WvStrings, and is a really handy way to parse strings.
WvString is an implementation of a simple and efficient printable-string class.
the data structure used by pre_select()/post_select() and internally by select().
A SelectRequest is a convenient way to remember what we want to do to a particular stream: read from ...
Provides support for forking processes.
void add_wvfork_callback(WvForkCallback cb)
Register a callback to be called during wvfork.
Various little string functions.
WvString ptr2str(void *ptr)
Converts a pointer into a string, like glibc's p formatter would do.