Rev 1469 | Rev 1533 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1469 | Rev 1532 | ||
---|---|---|---|
Line 39... | Line 39... | ||
39 | * Tetris input. |
39 | * Tetris input. |
40 | */ |
40 | */ |
41 | 41 | ||
42 | #include <sys/types.h> |
42 | #include <sys/types.h> |
43 | #include <sys/time.h> |
43 | #include <sys/time.h> |
- | 44 | #include <stdio.h> |
|
44 | 45 | ||
45 | #include <errno.h> |
46 | #include <errno.h> |
46 | #include <unistd.h> |
47 | #include <unistd.h> |
47 | #include <string.h> |
48 | #include <string.h> |
48 | 49 | ||
Line 88... | Line 89... | ||
88 | { |
89 | { |
89 | struct timeval starttv, endtv, *s; |
90 | struct timeval starttv, endtv, *s; |
90 | static ipc_call_t charcall; |
91 | static ipc_call_t charcall; |
91 | int rc; |
92 | int rc; |
92 | 93 | ||
93 | #define NILTZ ((struct timezone *)0) |
- | |
94 | - | ||
95 | /* |
94 | /* |
96 | * Someday, select() will do this for us. |
95 | * Someday, select() will do this for us. |
97 | * Just in case that day is now, and no one has |
96 | * Just in case that day is now, and no one has |
98 | * changed this, we use a temporary. |
97 | * changed this, we use a temporary. |
99 | */ |
98 | */ |
100 | if (tvp) { |
99 | if (tvp) { |
101 | (void) gettimeofday(&starttv, NILTZ); |
100 | (void) gettimeofday(&starttv, NULL); |
102 | endtv = *tvp; |
101 | endtv = *tvp; |
103 | s = &endtv; |
102 | s = &endtv; |
104 | } else |
103 | } else |
105 | s = NULL; |
104 | s = NULL; |
106 | again: |
105 | again: |
107 | if (!lastchar) { |
106 | if (!lastchar) { |
108 | if (!getchar_inprog) |
107 | if (!getchar_inprog) |
109 | getchar_inprog = async_send_2(1,CONSOLE_GETCHAR,0,0,&charcall); |
108 | getchar_inprog = async_send_2(1,CONSOLE_GETCHAR,0,0,&charcall); |
- | 109 | if (!s) |
|
- | 110 | async_wait_for(getchar_inprog, &rc); |
|
110 | if (async_wait_timeout(getchar_inprog, &rc, s->tv_usec) == ETIMEOUT) { |
111 | else if (async_wait_timeout(getchar_inprog, &rc, s->tv_usec) == ETIMEOUT) { |
111 | tvp->tv_sec = 0; |
112 | tvp->tv_sec = 0; |
112 | tvp->tv_usec = 0; |
113 | tvp->tv_usec = 0; |
113 | return (0); |
114 | return (0); |
114 | } |
115 | } |
115 | getchar_inprog = 0; |
116 | getchar_inprog = 0; |
Line 118... | Line 119... | ||
118 | } |
119 | } |
119 | lastchar = IPC_GET_ARG1(charcall); |
120 | lastchar = IPC_GET_ARG1(charcall); |
120 | } |
121 | } |
121 | if (tvp) { |
122 | if (tvp) { |
122 | /* since there is input, we may not have timed out */ |
123 | /* since there is input, we may not have timed out */ |
123 | (void) gettimeofday(&endtv, NILTZ); |
124 | (void) gettimeofday(&endtv, NULL); |
124 | TV_SUB(&endtv, &starttv); |
125 | TV_SUB(&endtv, &starttv); |
125 | TV_SUB(tvp, &endtv); /* adjust *tvp by elapsed time */ |
126 | TV_SUB(tvp, &endtv); /* adjust *tvp by elapsed time */ |
126 | } |
127 | } |
127 | return (1); |
128 | return (1); |
128 | } |
129 | } |