[rkward-cvs] SF.net SVN: rkward: [1418] trunk/rkward/rkward/scriptbackends
tfry at users.sourceforge.net
tfry at users.sourceforge.net
Wed Feb 21 12:33:55 UTC 2007
Revision: 1418
http://svn.sourceforge.net/rkward/?rev=1418&view=rev
Author: tfry
Date: 2007-02-21 04:33:55 -0800 (Wed, 21 Feb 2007)
Log Message:
-----------
Make sure to deal with transmissions that did not fit into the buffer in one piece.
This code is getting ugly, and would need to be reworked, but it seems to work ok, now.
This commit necessiatates a make install
Modified Paths:
--------------
trunk/rkward/rkward/scriptbackends/common.php
trunk/rkward/rkward/scriptbackends/phpbackend.cpp
trunk/rkward/rkward/scriptbackends/phpbackend.h
Modified: trunk/rkward/rkward/scriptbackends/common.php
===================================================================
--- trunk/rkward/rkward/scriptbackends/common.php 2007-02-20 05:27:14 UTC (rev 1417)
+++ trunk/rkward/rkward/scriptbackends/common.php 2007-02-21 12:33:55 UTC (rev 1418)
@@ -16,7 +16,7 @@
}
function getInput ($prompt) {
- fputs (STDOUT, "#RKEND#\n" . $prompt);
+ fputs (STDOUT, "#RKEND#\n" . $prompt . "#RKQEND#\n");
fflush (STDOUT);
while (1) {
if (feof (STDIN)) die (); // if the parent process exits unexpectedly, make sure the PHP-process gets killed
Modified: trunk/rkward/rkward/scriptbackends/phpbackend.cpp
===================================================================
--- trunk/rkward/rkward/scriptbackends/phpbackend.cpp 2007-02-20 05:27:14 UTC (rev 1417)
+++ trunk/rkward/rkward/scriptbackends/phpbackend.cpp 2007-02-21 12:33:55 UTC (rev 1418)
@@ -32,6 +32,7 @@
php_process = 0;
eot_string="#RKEND#\n";
+ eoq_string="#RKQEND#\n";
busy_writing = false;
busy = false;
}
@@ -196,42 +197,53 @@
void PHPBackend::gotOutput (KProcess *, char* buf, int len) {
RK_TRACE (PHP);
- QString output = buf;
+ RK_DO (qDebug ("PHP transmission:\n%s", buf), PHP, DL_DEBUG);
+
+ output_raw_buffer += buf;
QString request;
QString data;
- int i;
- bool have_data = true;;
+ int i, j;
+ bool have_data = true;
bool have_request = false;
-
+
// is there a request in the output stream?
- if ((i = output.find (eot_string)) >= 0) {
- have_request = true;
- // is there also pending data?
- if (i) {
- data = output.left (i);
- } else {
- have_data = false;
+ if ((i = output_raw_buffer.find (eot_string)) >= 0) {
+ if ((j = output_raw_buffer.find (eoq_string, i)) >= 0) {
+ have_request = true;
+ // is there also pending data?
+ if (i) {
+ data = output_raw_buffer.left (i);
+ } else {
+ have_data = false;
+ }
+ int start = i + eot_string.length ();
+ request = output_raw_buffer.mid (start, j - start);
+ output_raw_buffer = QString::null;
}
- request = output.mid (i + eot_string.length (), len);
} else {
- data = output;
+ data = output_raw_buffer;
}
- RK_DO (qDebug ("request: %s\ndata: %s", request.latin1 (), data.latin1 ()), PHP, DL_DEBUG);
// pending data is always first in a stream, so process it first, too
if (have_data) {
if (!startup_done) {
php_process->detach ();
- KMessageBox::error (0, i18n ("There has been an error\n(\"%1\")\nwhile starting up the PHP backend. Most likely this is due to either a bug in RKWard or an invalid setting for the location of the PHP support files. Check the settings (Settings->Configure Settings->PHP backend) and try again.").arg (data.stripWhiteSpace ()), i18n ("PHP-Error"));
+ KMessageBox::error (0, i18n ("There has been an error\n(\"%1\")\nwhile starting up the PHP backend. Most likely this is due to either a bug in RKWard or an invalid setting for the location of the PHP support files. Check the settings (Settings->Configure Settings->PHP backend) and try again.").arg (output_raw_buffer.stripWhiteSpace ()), i18n ("PHP-Error"));
emit (haveError ());
destroy ();
return;
}
-
+ }
+
+ if (!have_request) {
+ // output is not finished, yet.
+ // return and wait for more data to come in
+ RK_DO (qDebug ("PHP transmission not complete, yet"), PHP, DL_DEBUG);
+ return;
+ } else {
_output.append (data);
- }
-
- if (have_request) {
+ RK_DO (qDebug ("request: %s\ndata: %s", request.latin1 (), data.latin1 ()), PHP, DL_DEBUG);
+
if (request == "requesting code") {
startup_done = true;
busy = false;
@@ -284,8 +296,9 @@
emit (haveError ());
destroy ();
return;
+ } else {
+ RK_DO (qDebug ("unrecognized request from PHP backend: \"%s\"", request), PHP, DL_ERROR);
}
- return;
}
}
Modified: trunk/rkward/rkward/scriptbackends/phpbackend.h
===================================================================
--- trunk/rkward/rkward/scriptbackends/phpbackend.h 2007-02-20 05:27:14 UTC (rev 1417)
+++ trunk/rkward/rkward/scriptbackends/phpbackend.h 2007-02-21 12:33:55 UTC (rev 1418)
@@ -57,8 +57,10 @@
void tryNextFunction ();
void tryWriteData ();
KProcess *php_process;
-/// The string singalling the end of transmission to PHP. TODO: make static
+/// The string singalling the end of transmission to/from PHP. TODO: make static
QString eot_string;
+/// The string singalling the end of request from PHP. TODO: make static
+ QString eoq_string;
/** actually only one piece of data gets requested at a time. However, sometimes it takes a while until we realize (via doneWriting ()) that the last piece was transmitted ok (we have to keep a write buffer until then). So it may happen, that a new piece of information was requested, before we have completed the process for the previous one. Hence we use a FIFO stack just like for the commands (though it's handled slightly differently). */
QStringList data_stack;
/// write buffer for the current command
@@ -66,6 +68,7 @@
bool busy_writing;
bool doing_command;
bool startup_done;
+ QString output_raw_buffer;
struct PHPCommand {
/// the command string
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the rkward-tracker
mailing list