[FreeNX-kNX] [PATCH 2/5] Fixes to read from stdout

Otavio Salvador otavio at ossystems.com.br
Fri Nov 7 17:10:24 UTC 2008


From: Luis Gustavo S. Barreto <gustavo at ossystems.com.br>

Signed-off-by: Otavio Salvador <otavio at ossystems.com.br>
---
 nxcl/lib/notQt.cpp |   38 ++++++++++++++++++++++----------------
 1 files changed, 22 insertions(+), 16 deletions(-)

diff --git a/nxcl/lib/notQt.cpp b/nxcl/lib/notQt.cpp
index b362348..df3c964 100644
--- a/nxcl/lib/notQt.cpp
+++ b/nxcl/lib/notQt.cpp
@@ -30,6 +30,7 @@ extern "C" {
 #include <signal.h>
 }
 #include <stdlib.h>
+#include <cstring>
 
 #include "../config.h"
 #include "notQt.h"
@@ -290,23 +291,28 @@ notQProcess::probeProcess (void)
     string
 notQProcess::readAllStandardOutput (void)
 {
-    string s;
-    int bytes = 0;
-    char c;
-    struct pollfd p;
+	string s;
+	char chr[1024];
+	memset(chr, 0, 1024);
+
+	struct pollfd p;
+	p.fd = this->childToParent[READING_END];
+	p.events = POLLIN;
+
+	do {
+		p.revents = 0;
+
+		if (poll(&p, 1, 0) == -1)
+			continue;
+
+		int bytes;
+		if ((bytes = read(this->childToParent[READING_END], &chr, 1024)) >= 1)
+			s.append(chr);
+	} while ((p.revents & POLLIN) == 0);
+
+	// debug only
+	cout << s;
 
-    p.fd = this->childToParent[READING_END];
-    p.events = POLLIN | POLLPRI;
-    // We know we have at least one character to read, so seed revents
-    p.revents = POLLIN;
-    while (p.revents & POLLIN || p.revents & POLLPRI) {
-        // This read of 1 byte should never block
-        if ((bytes = read (this->childToParent[READING_END], &c, 1)) == 1) {
-            s.append (1, c);
-        }
-        p.revents = 0;
-        poll (&p, 1, 0);
-    }
     return s;
 }
 
-- 
1.6.0.3.640.g6331a




More information about the FreeNX-kNX mailing list