[Cluster-devel] conga/ricci/common Module.cpp executils.cpp
rmccabe at sourceware.org
rmccabe at sourceware.org
Sat Jun 2 04:28:49 UTC 2007
CVSROOT: /cvs/cluster
Module name: conga
Branch: EXPERIMENTAL
Changes by: rmccabe at sourceware.org 2007-06-02 04:28:49
Modified files:
ricci/common : Module.cpp executils.cpp
Log message:
be smarter about parsing incoming requests
Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/common/Module.cpp.diff?cvsroot=cluster&only_with_tag=EXPERIMENTAL&r1=1.5.8.1&r2=1.5.8.2
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/common/executils.cpp.diff?cvsroot=cluster&only_with_tag=EXPERIMENTAL&r1=1.8&r2=1.8.2.1
--- conga/ricci/common/Module.cpp 2007/06/01 23:12:22 1.5.8.1
+++ conga/ricci/common/Module.cpp 2007/06/02 04:28:48 1.5.8.2
@@ -253,56 +253,70 @@
int
__stdin_out_module_driver(Module& module)
{
- unsigned int time_beg = time_mil();
- String data;
+ unsigned int time_beg = time_mil();
+ String data;
- while (time_mil() < time_beg + timeout) {
- poll_fd poll_data;
- poll_data.fd = 0;
- poll_data.events = POLLIN;
- poll_data.revents = 0;
+ while (time_mil() < time_beg + timeout) {
+ poll_fd poll_data;
+ poll_data.fd = 0;
+ poll_data.events = POLLIN;
+ poll_data.revents = 0;
- // wait for events
- int ret = poll(&poll_data, 1, 500);
- if (ret == 0) {
- // continue waiting
- continue;
- } else if (ret == -1) {
- if (errno == EINTR)
- continue;
- else
- throw String("poll() error");
- }
-
- // process event
- if (poll_data.revents & POLLIN) {
- char buff[4096];
- int ret = read(poll_data.fd, buff, sizeof(buff));
- if (ret == -1) {
- if (errno == EINTR)
- continue;
- throw String("error reading stdin");
- }
- try {
- data.append(buff, ret);
- shred(buff, sizeof(buff));
- XMLObject request = parseXML(data);
- XMLObject response = module.process(request);
- cout << generateXML(response) << endl;
- return 0;
- } catch ( ... ) {
- shred(buff, sizeof(buff));
- }
- continue;
- }
- if (poll_data.revents & (POLLERR | POLLHUP | POLLNVAL))
- throw String("stdin error???");
+ // wait for events
+ int ret = poll(&poll_data, 1, 500);
+
+ if (ret == 0) {
+ /*
+ ** We may be done if the total input length is a multiple of
+ ** the buffer size.
+ */
+ if (data.length() > 0) {
+ try {
+ XMLObject request = parseXML(data);
+ XMLObject response = module.process(request);
+ cout << generateXML(response) << endl;
+ return 0;
+ } catch ( ... ) { }
+ }
+ // continue waiting
+ continue;
+ } else if (ret == -1) {
+ if (errno == EINTR)
+ continue;
+ else
+ throw String("poll() error: ") + String(strerror(errno));
+ }
- } // while
+ // process event
+ if (poll_data.revents & POLLIN) {
+ char buff[4096];
+ int ret = read(poll_data.fd, buff, sizeof(buff));
+ if (ret == -1) {
+ if (errno == EINTR)
+ continue;
+ throw String("error reading stdin: ") + String(strerror(errno));
+ }
+
+ if ((size_t) ret < sizeof(buff)) {
+ try {
+ data.append(buff, ret);
+ shred(buff, sizeof(buff));
+ XMLObject request = parseXML(data);
+ XMLObject response = module.process(request);
+ cout << generateXML(response) << endl;
+ return 0;
+ } catch ( ... ) {
+ shred(buff, sizeof(buff));
+ }
+ }
+ continue;
+ }
+ if (poll_data.revents & (POLLERR | POLLHUP | POLLNVAL))
+ throw String("stdin error: ") + String(strerror(errno));
+ } // while
// cout << data << endl;
-
- throw String("invalid input");
+ throw String("invalid input");
}
--- conga/ricci/common/executils.cpp 2007/03/05 20:06:50 1.8
+++ conga/ricci/common/executils.cpp 2007/06/02 04:28:48 1.8.2.1
@@ -218,7 +218,7 @@
if (poll_info.revents & POLLIN) {
try {
- char data_in[1024];
+ char data_in[4096];
int ret = read(fd, data_in, sizeof(data_in));
if (ret < 0)
return;
More information about the Cluster-devel
mailing list