We are leveraging POCO for our server, and making use of Poco::Net::MultipartWriter, to handle our responses for this one type of inquiry. When a client calls close on the underlying socket on their side our server crashes with an access violation however when they call shutdown on the socket this doesn't happen. I am wondering if there is something we are fundamentally doing wrong with the POCO code or if there is a better way for us to work with it to prevent this. The following is snippet of what we are doing:
class HTTPSender
{
public:
///..... Code here omitted
private:
///..... Code here omitted
void _send(CU::BorrowedPtr<const Data> Data);
Poco::Net::HTTPServerResponse& _response;
std::unique_ptr<Poco::Net::MultipartWriter> _writer;
std::ostream* _outputStream;
};
void HTTPSender::_send(BorrowedPtr<const Data> Data)
{
if(_writer == nullptr)
{
const string boundary = "myboundary";
addCommonHeaderFields(_response, HTTPResponse::HTTP_OK);
_response.setContentType(format("text/html; boundary=--%s", boundary.c_str()));
_outputStream = &_response.send();
_writer.reset(new MultipartWriter(*_outputStream, boundary));
}
MessageHeader header;
_addFrameHeaderFields(&header, Data);
header.add(HTTPMessage::CONTENT_TYPE, _getContentType(Data->Format));
header.add(HTTPMessage::CONTENT_LENGTH, to<string>(Data->length));
_writer->nextPart(header);
_outputStream->write((const char*)Data->buffer, (std::streamsize)Data->length);
}
The send method is called every time we have more of our data available which happens on a periodic interval. The Access violation always occurs in the _outputStream::write method. And given that it only happens when the client call close as opposed to shutdown it makes me think we need to adjust our approach. Additionally I have inspected the ostream::good flag before and after the debugger breaks on the access violation but in both cases it is true.
Thank you!