Monday, November 08, 2010 at 12:01 AM.
system.verbs.apps.netEvents.listenThread
on listenThread (port, stream, callback, refcon, onceOnly = false) { local (timedOut); netEvents.init (); <<make sure all the tables we need are set up loop { timedOut = false; stream = appleEvent (netEvents.id, 'WAPI', 'LIST', '----', short (port), 'REFC', long (refcon), 'TIME', 0); user.inetd.listens.[port].ref = user.inetd.listens.[port].ref + stream; // help for inetd w/NetEvents local (adrtable = @user.netEvents.listens.[stream]); new (tabletype, adrtable); adrtable^.ready = false; adrtable^.refcon = refcon; adrTable^.thread = thread.getCurrentID(); local (tc = clock.ticks ()); while not adrtable^.ready { if clock.ticks () > (tc + 1800) { local (status, bytespending); status = netEvents.statusStream (stream, @bytespending); if status == "INACTIVE" { timedOut = true; break}; tc = clock.ticks ()}; sys.systemTask ()}; if not timedOut { callback^ (stream, refcon)}; user.inetd.listens.[port].ref = user.inetd.listens.[port].ref - stream; // help for inetd w/NetEvents delete (@user.netEvents.listens.[stream]); if onceOnly { return (true)}}}
This listing is for code that runs in the OPML Editor environment. I created these listings because I wanted the search engines to index it, so that when I want to look up something in my codebase I don't have to use the much slower search functionality in my object database. Dave Winer.