[comp.unix.sysv386] Curses bug in halfdelay

weave@brahms.udel.edu (Ken Weaverling) (12/24/90)

I am trying to get the halfdelay() routine in curses to implement a timeout
on a getch() call. It simply blocks and doesn't return. This same test program
I set up (included below) works fine on a Sun 4 using /usr/5bin/cc to compile.
I have tried cc and gcc on my box, but none work.

Machine and OS specifics:

Prime EXL 325, 386 Multibus II box
AT&T Unix Sys V 3.1 version 2

What I have tried to resolve problem:

Compiled on a Sun 4 with /usr/5bin/cc. Works as advertised
Tried sending an alarm (signal 14) to the process to see if some code in curses
set an alarm() and signal trap. No go, the program aborted with an Alarm Call
Read the manual over and over to see if I was missing something.


Since this works on a Sun, I doubt that the problem is with my code. So I'd
like to determine if the problem is limited to my machine, or is a bug that
appears in other 386 UNIX implementations.

Another question: If this is a bug and I have to give up hope on this, I was
planning on just using an alarm() for one second just before the call to 
getch(). Is there any problems that can crop up with this approach? 

I don't want to use nodelay() to stop blocking since I don't want to run
some tight CPU intensive loop looking for something to do. 

Thanks and Happy Whatever! (sample code next)


#include <curses.h>

main() {
  char linebuf[80];
  int keypress = 0;

  initscr();
  noecho();  /* I have also tried leaving this out and putting in cbreak() */
  halfdelay(20);
  addstr("Ready to do keyboard timeout test. Press q when done.");
  while (keypress != 'q') {
    addstr("\nEnter a key: ");
    keypress = getch();
    if (keypress == ERR) {
      addstr("\nYou did not respond in time!");
      refresh();
      sleep(1);
    }
    else {
      sprintf(linebuf, "\nYou pressed the %c key", keypress);
      addstr(linebuf);
      refresh();
      sleep(1);
    }
  }
  endwin();
}
-- 
>>>---> Ken Weaverling  >>>---->  weave@brahms.udel.edu

weave@brahms.udel.edu (Ken Weaverling) (12/25/90)

In article <17068@brahms.udel.edu> I (Ken Weaverling) write:

>I am trying to get the halfdelay() routine in curses to implement a timeout
>on a getch() call. It simply blocks and doesn't return. This same test program
>I set up (included below) works fine on a Sun 4 using /usr/5bin/cc to compile.
>I have tried cc and gcc on my box, but none work.
>
>Machine and OS specifics:
>
>Prime EXL 325, 386 Multibus II box
>AT&T Unix Sys V 3.1 version 2

I also just tried this on a Unisys u6000 box running AT&T Sys V/386 3.2 (note,
later version than mine).  The code STILL doesn't timeout on the read but
blocks forever....

Is it a safe work-around for me to use alarm() and trap the alarm signal? 
What I would do is call alarm() right before the getch() and trap the alarm
signal, then set a flag in it and return. The getch() would be terminated
after the timeout period.  Or is there a better method? Again, using nodelay
would force me to poll getch() and that would chew CPU cycles needlessly...

Thanks!

-- 
>>>---> Ken Weaverling  >>>---->  weave@brahms.udel.edu

darcy@druid.uucp (D'Arcy J.M. Cain) (12/29/90)

In article <17070@brahms.udel.edu> Ken Weaverling writes:
>In article <17068@brahms.udel.edu> I (Ken Weaverling) write:
>>I am trying to get the halfdelay() routine in curses to implement a timeout
>>on a getch() call. It simply blocks and doesn't return. This same test program
>Is it a safe work-around for me to use alarm() and trap the alarm signal? 
>What I would do is call alarm() right before the getch() and trap the alarm
>signal, then set a flag in it and return. The getch() would be terminated
>after the timeout period.  Or is there a better method? Again, using nodelay
>would force me to poll getch() and that would chew CPU cycles needlessly...

Here's a radical thought.  Complain to your vendor that the product is broken
and have them fix it.  I use ESIX and when I reported the problem they
fixed it and sent me a new copy of the library.

-- 
D'Arcy J.M. Cain (darcy@druid)     |
D'Arcy Cain Consulting             |   There's no government
West Hill, Ontario, Canada         |   like no government!
+1 416 281 6094                    |

weave@brahms.udel.edu (Ken Weaverling) (12/30/90)

In article <1990Dec29.153528.18008@druid.uucp> darcy@druid.uucp (D'Arcy J.M. Cain) writes:
>In article <17068@brahms.udel.edu> I (Ken Weaverling) write:
>>I am trying to get the halfdelay() routine in curses to implement a timeout
>>on a getch() call. It simply blocks and doesn't return. This same test program
>
>Here's a radical thought.  Complain to your vendor that the product is broken
>and have them fix it.  I use ESIX and when I reported the problem they
>fixed it and sent me a new copy of the library.

I plan to eventually, but getting it fixed won't solve the problem if the
bug is widespread. My vendor is Prime who is still pushing SysV/386 3.1.

I have tried this on a Unisys u6000 which runs 3.2 and it doesn't work there.
If the bug is widespread, I don't want to write a program that uses that
function cause my program will then break on one of these other systems.

Thanks for letting me know it works on ESIX though -- now.
-- 
>>>---> Ken Weaverling  >>>---->  weave@brahms.udel.edu