Monday, November 08, 2010 at 12:04 AM.
system.verbs.builtins.odbServer.daemon.daemon
on daemon (adrparams) {
<<adrparams is the address of a table containing
<<client -- a 4-byte encoded IP address, call netevents.addressToName to convert it to a string
<<ready -- always true
<<refcon -- always 0
<<stream -- the stream id for this NetEvents message
scratchpad.odbServerParams = adrparams^;
local (s, x, bytespending);
local (endcommand = "endodbservercommand");
local (timeout = clock.ticks () + (user.odbserver.prefs.timeoutsecs * 60));
loop {
case netEvents.statusStream (adrparams^.stream, @bytespending) {
"CLOSING";
"CLOSED";
"INACTIVE" {
break};
"DATA" {
x = netEvents.readStream (adrParams^.stream, bytespending);
s = s + x;
if s endswith endcommand {
s = string.mid (s, 1, sizeOf (s) - sizeOf (endcommand));
msg ("Command received...");
break}}};
if clock.ticks () > timeout {
s = "";
break}};
local (response = odbServer.commandHandle (s, adrparams));
loop {
local (chunksize = 5 * 1024);
if sizeof (response) <= chunksize {
netEvents.writeStream (adrparams^.stream, response);
break};
netEvents.writeStream (adrparams^.stream, string.mid (response, 1, chunksize));
response = string.delete (response, 1, chunksize)}}
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.