From mboxrd@z Thu Jan 1 00:00:00 1970 From: rmccabe@sourceware.org Date: 2 Jun 2007 04:28:49 -0000 Subject: [Cluster-devel] conga/ricci/common Module.cpp executils.cpp Message-ID: <20070602042849.17702.qmail@sourceware.org> List-Id: To: cluster-devel.redhat.com MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 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;