This is the mail archive of the kawa@sourceware.cygnus.com mailing list for the Kawa project. See the Kawa home page for more information.


[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index] [Subject Index] [Author Index] [Thread Index]

Re: Why GuiConsole hangs



> Of course, Sun's jacl manages to put up a command-line prompt
> AND run background threads, even GUI stuff, so I looked
> through the sources to find out how.

Ah - that is helpful.  I implemented the ideas from Jacl,
and it seems to work [see below] - except for one problem:
It does not handle end-of-file properly.  If I type a ^D at
the beginning of a line, the stream is not available()
until I type an <Enter>.  And then the stream is available,
Kawa wakes up, exits, and the <Enter> is passed on to the Shell.

So I guess the question is whether Jacl manages to correctly
handle EOF, or is this unsolvable?

So I gues the question is which is a bigger problem:
(a) can't fix GUI with reading from System.in
(b) can't recohmize eof from System.in properly.

If we can't fix both, which is more important?
My current inclination is that (a) is more important to fix.

Another question:  Has anyone gotten the window interface
(GuiConsole / -w / scheme-window) to work under Windows95?

	--Per Bothner
Cygnus Solutions     bothner@cygnus.com     http://www.cygnus.com/~bothner

package kawa.lang;
import java.io.*;

public class SysInPort extends TtyInPort
{
  InputStream inStream;

  public SysInPort (InputStream inStream, String name, OutPort tie)
  {
    super(inStream, name, tie);
    this.inStream = inStream;
  }

  public int fill (char[] buffer, int off, int len) throws java.io.IOException
  {
    /* This explanation and work-around comes frm jacl 1.0's Shell.java:
     *
     * On Unix platforms, System.in.read() will block the delivery of
     * of AWT events. We must make sure System.in.available() is larger
     * than zero before attempting to read from System.in. Since
     * there is no asynchronous IO in Java, we must poll the System.in
     * every 100 milliseconds.
     */

    try
      {
	while (inStream.available() == 0)
	  Thread.currentThread().sleep(100);

	/*
	if (! in.ready())
	  {
	    for (;;)
	      {
		if (inStream.available() > 0)
		  break;
		try
		  {
		    Thread.currentThread().sleep(100);
		  }
		catch (java.lang.InterruptedException ex)
		  {
		  }
	      }
	  }
	*/
      }
    catch (java.lang.InterruptedException ex)
      {
      }
    catch (java.io.IOException ex)
      {
	// available or ready does not seem to be supported or working.
      }
    return super.fill(buffer, off, len);
  }
}