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...)
42 WvIStreamList::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();
59 WvIStreamList::~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);
272 void WvIStreamList::onfork(pid_t p)
277 globallist.zap(
false);
283 void WvIStreamList::add_debugger_commands()
285 WvStreamsDebugger::add_command(
"globallist", 0, debugger_globallist_run_cb, 0);
289 WvString WvIStreamList::debugger_globallist_run_cb(WvStringParm cmd,
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;