bug-ncurses
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: is ncurses library reentrant?


From: Francesco Esposito
Subject: Re: is ncurses library reentrant?
Date: Tue, 13 Feb 2007 14:06:29 +0100

Hi all,
I think that will use wtimeout(Window*, int delay) before of wgetch use and when I receive the ERR or OK code I will perform the window refresh.


 
2007/2/13, G Hasse <address@hidden>:
On Tue, Feb 13, 2007 at 07:25:18AM -0500, Thomas Dickey wrote:
> On Tue, 13 Feb 2007, Francesco Esposito wrote:
>
> >Dear Thomas,
> >thanks for your support!
> >My specific problem is that: I must to develop a ncurses
> >application that
> >show a clock sub-window, with current time(auto-update), in a
> >main-window
> >without block the user UI interaction.
> >Do you need any tips(or C/C++ code) that made this?
>
> You can use nonblocking I/O, e.g., setup getch() to read with a
> short blocking time, and wrap getch() in a function that
> periodically updates
> the clock.  Several of the test programs in ncurses use nonblocking
> I/O,
> e.g., nodelay() with napms() or wtimeout() to poll for keyboard input
> while updating the display.

I understand why ncurses use getch but the problem is that this
library call is over buffered input. Eg the operating system can
decide when to deliver the charachter to the application.

The correct way would be to look for events with a select...

Something like

---

// Register filedescriptors for select
// This is from a socket application...

FD_ZERO(&ifds);
FD_SET(STDIN_FILENO, &ifds );
FD_SET(serv_sock, &ifds );
maxfd = serv_sock;

printf("New socket %d\n", maxfd );
fflush(stdout);

for(;;) {
   int fd = -1;
   int i;
   int numfds = 0;

   struct timeval to = { 0, 0 };

   // Temporary fd_set
   fd_set tifds = ifds;

   numfds = select( maxfd+1, &tifds, NULL, NULL, NULL );

    // Handle event here


  }

---  the complete application uppon request...

Threaded application and reentrant functions just make things
harder...

--
Göran Hasse

----------------------------------------------------------------
Göran Hasse            email: address@hidden     Tel: 08-6949270
Raditex AB             http://www.raditex.se
Planiavägen 15, 1tr                             Mob: 070-5530148
131 34  NACKA, SWEDEN                         OrgNr: 556240-0589
VAT: SE556240058901
------------------------------------------------------------------



reply via email to

[Prev in Thread] Current Thread [Next in Thread]