* (no subject)
@ 2020-03-13 3:21 Amavect .
2020-03-13 7:51 ` Anthony Martin
0 siblings, 1 reply; 3+ messages in thread
From: Amavect . @ 2020-03-13 3:21 UTC (permalink / raw)
To: 9front
All,
I'm trying to write a gui program with using both keyboard(2) and stdin.
It appears that there's a race between /dev/cons and stdin.
Shouldn't only keyboard(2) get the character?
Example: http://okturing.com/src/7981/body
#include <u.h>
#include <libc.h>
#include <draw.h>
#include <cursor.h>
#include <thread.h>
#include <keyboard.h>
#include <mouse.h>
void
stdinproc(void *aux)
{
Channel *c;
char in;
long n;
c = aux;
for(;;){
n = read(0, &in, sizeof(in));
if(n != 0){
send(c, &in);
}else{
print("stdin: closed?");
threadexitsall(nil);
}
}
}
void
threadmain(int, char **)
{
Keyboardctl *kctl;
Rune r;
char inc;
Channel *stdinc;
stdinc = chancreate(sizeof(char), 8);
proccreate(stdinproc, stdinc, 0x2000);
if((kctl = initkeyboard(nil)) == nil)
sysfatal("%r");
enum { KEYS, STDIN, NONE };
Alt alts[] = {
[KEYS] = {kctl->c, &r, CHANRCV},
[STDIN] = {stdinc, &inc, CHANRCV},
[NONE] = {nil, nil, CHANEND}
};
for(;;){
switch(alt(alts)){
case KEYS:
if(r == Kdel)
threadexitsall(nil);
print("keys: %C\n", r);
break;
case STDIN:
print("stdin: %c\n", inc);
break;
case NONE:
print("NOPE\n");
break;
}
}
}
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re:
2020-03-13 3:21 Amavect .
@ 2020-03-13 7:51 ` Anthony Martin
2020-03-14 2:56 ` [9front] Re: Amavect .
0 siblings, 1 reply; 3+ messages in thread
From: Anthony Martin @ 2020-03-13 7:51 UTC (permalink / raw)
To: 9front
"Amavect ." <amavect@gmail.com> once said:
> I'm trying to write a gui program with using both keyboard(2) and stdin.
> It appears that there's a race between /dev/cons and stdin.
> Shouldn't only keyboard(2) get the character?
> Example: http://okturing.com/src/7981/body
What output do you expect when standard input is /dev/cons?
Both the internal keyboard(2) process and your stdinproc are
reading from the same underlying file.
Try redirecting the standard input of your program from another
file and and report back the results.
Cheers,
Anthony
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [9front] Re:
2020-03-13 7:51 ` Anthony Martin
@ 2020-03-14 2:56 ` Amavect .
0 siblings, 0 replies; 3+ messages in thread
From: Amavect . @ 2020-03-14 2:56 UTC (permalink / raw)
To: 9front
Ah, it's still reading /dev/cons through stdin.
I've been pointed to reading /dev/kbd directly.
Thanks for the help.
Thanks,
Amavect
On Fri, Mar 13, 2020 at 2:53 AM Anthony Martin <ality@pbrane.org> wrote:
>
> "Amavect ." <amavect@gmail.com> once said:
> > I'm trying to write a gui program with using both keyboard(2) and stdin.
> > It appears that there's a race between /dev/cons and stdin.
> > Shouldn't only keyboard(2) get the character?
> > Example: http://okturing.com/src/7981/body
>
> What output do you expect when standard input is /dev/cons?
> Both the internal keyboard(2) process and your stdinproc are
> reading from the same underlying file.
>
> Try redirecting the standard input of your program from another
> file and and report back the results.
>
> Cheers,
> Anthony
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-03-14 2:57 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-13 3:21 Amavect .
2020-03-13 7:51 ` Anthony Martin
2020-03-14 2:56 ` [9front] Re: Amavect .
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).