diff options
author | Adrian Kummerlaender | 2014-10-16 19:20:04 +0200 |
---|---|---|
committer | Adrian Kummerlaender | 2014-10-16 19:20:04 +0200 |
commit | bc48696d7f463d0a230193f2173ec8516a2ca4b0 (patch) | |
tree | 152f1c9cf1009b3c3b7067704683ee1c9e88ac68 /src/function | |
parent | a4a7ee4f614e85f9952a4a8ea418e263512fc2ba (diff) | |
download | InputXSLT-bc48696d7f463d0a230193f2173ec8516a2ca4b0.tar InputXSLT-bc48696d7f463d0a230193f2173ec8516a2ca4b0.tar.gz InputXSLT-bc48696d7f463d0a230193f2173ec8516a2ca4b0.tar.bz2 InputXSLT-bc48696d7f463d0a230193f2173ec8516a2ca4b0.tar.lz InputXSLT-bc48696d7f463d0a230193f2173ec8516a2ca4b0.tar.xz InputXSLT-bc48696d7f463d0a230193f2173ec8516a2ca4b0.tar.zst InputXSLT-bc48696d7f463d0a230193f2173ec8516a2ca4b0.zip |
Changed FunctionExternalCommand stream read order
* long outputs to stdout from child processes filled up the `boost::process::pistream` buffer and caused `write` to block
** this issue was circumvented by reading the stream into a `std::stringstream` instance before retrieving the blocking exit status
* modified document import implementation accordingly
Diffstat (limited to 'src/function')
-rw-r--r-- | src/function/external_command.cc | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/src/function/external_command.cc b/src/function/external_command.cc index 3819a43..40b02b9 100644 --- a/src/function/external_command.cc +++ b/src/function/external_command.cc @@ -15,19 +15,22 @@ namespace { using InputXSLT::XercesStringGuard; -inline xercesc::DOMNode* importDocumentElement( - boost::process::pistream& outputStream, - xercesc::DOMDocument* const domDocument -) { - std::stringstream xmlStream( +inline std::unique_ptr<std::stringstream> readOutput( + boost::process::pistream& outputStream) { + return std::make_unique<std::stringstream>( "<output>" + std::string( (std::istreambuf_iterator<char>(outputStream)), (std::istreambuf_iterator<char>()) ) + "</output>" ); +} +inline xercesc::DOMNode* importDocumentElement( + std::stringstream* const outputStream, + xercesc::DOMDocument* const domDocument +) { xercesc::XercesDOMParser parser; - parser.parse(xalan::XSLTInputSource(xmlStream)); + parser.parse(xalan::XSLTInputSource(*outputStream)); return domDocument->importNode( parser.getDocument()->getDocumentElement(), @@ -66,8 +69,11 @@ DomDocumentCache::document_ptr FunctionExternalCommand::constructDocument( inputStream.close(); } - boost::process::pistream& outputStream = commandProcess.get_stdout(); - boost::process::status status = commandProcess.wait(); + std::unique_ptr<std::stringstream> outputStream{ + readOutput(commandProcess.get_stdout()) + }; + + boost::process::status status = commandProcess.wait(); ResultNodeFacade result(domDocument.get(), "command"); result.setAttribute("executed", command); @@ -77,7 +83,7 @@ DomDocumentCache::document_ptr FunctionExternalCommand::constructDocument( try { result.setContent( importDocumentElement( - outputStream, + outputStream.get(), domDocument.get() )->getChildNodes() ); |