Subject: killing read-suspended tasks...

From: Andrew Wilson <[email-masked]>
Date: Sun, 28 Mar 1993 07:40:40 -0800

A while ago Killik posted a simplified version of a MOO client:

  c = open_network_connection(host, port);
  fork tid (0)
    while (1)
      notify(c, read(player));
    endwhile
  endfork
  while (typeof(line = read(c)) == STR)
    player:tell("", line);
  endwhile
  kill_task(tid);

and just for a laugh I wrote a little telnet verb:

	@program test:@telnet -d
	usage = "Usage: @telnet test to host port";
	WhereTo = $string_utils:explode(iobjstr);
	if (length(whereto) != 2)
		player:tell(usage);
		return;
	endif;

	host = Whereto[1];
	port = Whereto[2];

	c = open_network_connection(tostr(host), tonum(port));
	fork tid (0)
		while (1)
			notify(c, read(player));
		endwhile;
	endfork;
	while (typeof(line = read(c)) == STR)
		player:tell("", line);
	endwhile;
	kill_task(tid);
	player:tell("", "Done.");
	.

As you'd expect, the verb connects to a site and can send information
back and forwards adequately.  As a test I tried telnetting to LamdaMOO,
it worked fine.  But, after I typed '@quit', which caused the LambdaMOO 
server to disconnect my LambdaMOO player object, I was left with a hung
'terminal' on my own MOO.

My guess is that the kill_task() didn't stop the reader portion of the telnet
verb.  It 'seems' to remain active and keeps eating what I type. At the
time the kill_task is called the 'reader' task would seem to be suspended at
the read statement, waiting for me to type something.

So:

	- is tid's scope only within the fork endfork block.  Meaning that the
	  kill_task wouldn't work because tid was undefined.

	- is the server able to wake up a read suspended task in order to kill
	  it?

If kill_task can't be made to work then the only way to free the player's
'terminal' is to boot_player him!

What have I done wrong?

Andy.