[BRLTTY] [Nvda-dev] Braille support?
Samuel Thibault
samuel.thibault at ens-lyon.org
Sun Sep 28 15:18:22 EDT 2008
Samuel Thibault, le Tue 23 Sep 2008 03:01:28 +0200, a écrit :
> Now, about the CPU consumption, I've noticed something bad with my irda
> port: awaitInput doesn't wait. It may be that we are just missing and
> end of file condition, I'll investigate more later.
It's actually that ReadFile(0) doesn't wait. I've looked deep into the
comm documentation, and couldn't find any way to poll a comm handler...
There is WaitCommEvent but it doesn't accept a timeout, unless turning
the handle into overlapped mode, which would make the whole code a lot
messy... The only sane way I could find is the attached patch: use
ReadFile(1) and remember the character for later use. Lee and James,
could you try it?
Samuel
-------------- next part --------------
Index: Programs/serial.c
===================================================================
--- Programs/serial.c (r?vision 3933)
+++ Programs/serial.c (copie de travail)
@@ -163,6 +163,7 @@
#ifdef __MINGW32__
HANDLE fileHandle;
+ int pending;
#endif /* __MINGW32__ */
#ifdef __MSDOS__
@@ -1025,6 +1026,7 @@
if (!serialFlushAttributes(serial)) return 0;
#ifdef __MINGW32__
+ if (serial->pending != -1) return 1;
COMMTIMEOUTS timeouts = {MAXDWORD, 0, timeout, 0, 0};
DWORD bytesRead;
int ret;
@@ -1034,10 +1036,12 @@
return 0;
}
- ret = ReadFile(serial->fileHandle, &c, 0, &bytesRead, NULL);
- if (!ret)
- LogWindowsError("ReadFile");
- return ret;
+ ret = ReadFile(serial->fileHandle, &c, 1, &bytesRead, NULL);
+ if (bytesRead) {
+ serial->pending = c;
+ return 1;
+ }
+ return 0;
#else /* __MINGW32__ */
return awaitInput(serial->fileDescriptor, timeout);
#endif /* __MINGW32__ */
@@ -1055,21 +1059,27 @@
COMMTIMEOUTS timeouts = {MAXDWORD, 0, initialTimeout, 0, 0};
DWORD bytesRead;
- if (!(SetCommTimeouts(serial->fileHandle, &timeouts))) {
- LogWindowsError("SetCommTimeouts serialReadChunk1");
- setSystemErrno();
- return 0;
- }
+ if (serial->pending) {
+ * (unsigned char *) buffer = serial->pending;
+ serial->pending = -1;
+ bytesRead = 1;
+ } else {
+ if (!(SetCommTimeouts(serial->fileHandle, &timeouts))) {
+ LogWindowsError("SetCommTimeouts serialReadChunk1");
+ setSystemErrno();
+ return 0;
+ }
- if (!ReadFile(serial->fileHandle, buffer+*offset, count, &bytesRead, NULL)) {
- LogWindowsError("ReadFile");
- setSystemErrno();
- return 0;
- }
+ if (!ReadFile(serial->fileHandle, buffer+*offset, count, &bytesRead, NULL)) {
+ LogWindowsError("ReadFile");
+ setSystemErrno();
+ return 0;
+ }
- if (!bytesRead) {
- errno = EAGAIN;
- return 0;
+ if (!bytesRead) {
+ errno = EAGAIN;
+ return 0;
+ }
}
count -= bytesRead;
More information about the BRLTTY
mailing list