r2035
dslinux_amadeus at dslinux.in-berlin.de
dslinux_amadeus at dslinux.in-berlin.de
Fri Nov 9 14:04:15 CET 2007
Author: amadeus
Date: 2007-11-09 14:04:10 +0100 (Fri, 09 Nov 2007)
New Revision: 2035
Log:
Fix a nasty bug because of an ugly hack with a more ugly solution.
Modified: trunk/user/microwin/src/nanox/client.c
===================================================================
--- trunk/user/microwin/src/nanox/client.c 2007-11-07 20:55:58 UTC (rev 2034)
+++ trunk/user/microwin/src/nanox/client.c 2007-11-09 13:04:10 UTC (rev 2035)
@@ -151,7 +151,7 @@
nxFlushReq(0L,0);
while(v < ((char *) b + n)) {
- i = read(nxSocket, v, ((char *) b + n - v));
+ i = nxReadSocket(v, ((char *) b + n - v));
if ( i <= 0 ) {
if ( i == 0 ) {
/* We should maybe produce an event here,
Modified: trunk/user/microwin/src/nanox/nxproto.c
===================================================================
--- trunk/user/microwin/src/nanox/nxproto.c 2007-11-07 20:55:58 UTC (rev 2034)
+++ trunk/user/microwin/src/nanox/nxproto.c 2007-11-09 13:04:10 UTC (rev 2035)
@@ -100,6 +100,29 @@
} while ( todo > 0 );
}
+/* Buffer for "lost" bytes on poll operations */
+static char poll_buffer[256];
+static unsigned char poll_read = 0;
+static unsigned char poll_write = 0;
+
+/* Read a block of data on the socket from the nano-X server */
+int
+nxReadSocket(char *buf, int todo)
+{
+ int count = 0;
+ while (todo && (poll_read != poll_write)) {
+ *buf++ = poll_buffer[poll_read++];
+ count++;
+ todo--;
+ }
+ if (todo) {
+ int result = read(nxSocket, buf, todo);
+ if (result > 0)
+ count += result;
+ }
+ return count;
+}
+
/* Flush request buffer if required, possibly reallocate buffer size*/
void
nxFlushReq(long newsize, int reply_needed)
@@ -159,10 +182,15 @@
nxWriteSocket((char *)&req,sizeof(req));
- if ( reply_needed )
- while ( read(nxSocket, &c, 1) != 1 )
- ;
-
+ if ( reply_needed ) {
+ do {
+ /* wait for the response byte ("1") from the server */
+ while ( read(nxSocket, &c, 1) != 1 )
+ ;
+ if (c != 1)
+ poll_buffer[poll_write++] = c;
+ } while (c != 1);
+ }
reqbuf.bufptr = reqbuf.buffer;
if ( reqbuf.buffer + newsize > reqbuf.bufmax ) {
Modified: trunk/user/microwin/src/nanox/nxproto.h
===================================================================
--- trunk/user/microwin/src/nanox/nxproto.h 2007-11-07 20:55:58 UTC (rev 2034)
+++ trunk/user/microwin/src/nanox/nxproto.h 2007-11-09 13:04:10 UTC (rev 2035)
@@ -81,6 +81,7 @@
void nxAssignReqbuffer(char *buffer, long size);
void nxWriteSocket(char *buf, int todo);
int nxCalcStringBytes(void *str, int count, GR_TEXTFLAGS flags);
+int nxReadSocket(char *buf, int todo);
#if notyet
/* all replies share this header*/
More information about the dslinux-commit
mailing list