[BRLTTY] [Nvda-dev] Braille support?
Samuel Thibault
samuel.thibault at ens-lyon.org
Fri Oct 17 14:46:46 EDT 2008
Hello,
Samuel Thibault, le Sun 28 Sep 2008 21:18:22 +0200, a écrit :
> 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?
I had forgotten to initialize pending... Could you give a try to this
patch instead?
Samuel
-------------- next part --------------
Index: Programs/serial.c
===================================================================
--- Programs/serial.c (révision 3946)
+++ 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 != -1) {
+ * (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;
@@ -1377,6 +1387,9 @@
serial->pendingFlowControlProc = NULL;
serial->flowControlRunning = 0;
#endif /* HAVE_POSIX_THREADS */
+#ifdef __MINGW32__
+ serial->pending = -1;
+#endif /* __MINGW32__ */
LogPrint(LOG_DEBUG, "serial device opened: %s: fd=%d",
device,
More information about the BRLTTY
mailing list