mirror of
https://github.com/Telecominfraproject/wlan-cloud-lib-poco.git
synced 2025-11-01 02:57:51 +00:00
143 lines
3.0 KiB
C++
143 lines
3.0 KiB
C++
//
|
|
// ApacheStream.h
|
|
//
|
|
// $Id: //poco/1.4/ApacheConnector/src/ApacheStream.cpp#2 $
|
|
//
|
|
// Copyright (c) 2006-2011, Applied Informatics Software Engineering GmbH.
|
|
// and Contributors.
|
|
//
|
|
// Permission is hereby granted, free of charge, to any person or organization
|
|
// obtaining a copy of the software and accompanying documentation covered by
|
|
// this license (the "Software") to use, reproduce, display, distribute,
|
|
// execute, and transmit the Software, and to prepare derivative works of the
|
|
// Software, and to permit third-parties to whom the Software is furnished to
|
|
// do so, all subject to the following:
|
|
//
|
|
// The copyright notices in the Software and this entire statement, including
|
|
// the above license grant, this restriction and the following disclaimer,
|
|
// must be included in all copies of the Software, in whole or in part, and
|
|
// all derivative works of the Software, unless such copies or derivative
|
|
// works are solely in the form of machine-executable object code generated by
|
|
// a source language processor.
|
|
//
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
|
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
|
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
// DEALINGS IN THE SOFTWARE.
|
|
//
|
|
|
|
|
|
#include "ApacheStream.h"
|
|
#include "ApacheConnector.h"
|
|
#include "Poco/Exception.h"
|
|
|
|
|
|
using Poco::BufferedStreamBuf;
|
|
|
|
|
|
//
|
|
// ApacheStreamBuf
|
|
//
|
|
|
|
|
|
ApacheStreamBuf::ApacheStreamBuf(ApacheRequestRec* pApacheRequest, bool haveData):
|
|
BufferedStreamBuf(STREAM_BUFFER_SIZE, std::ios::in | std::ios::out),
|
|
_pApacheRequest(pApacheRequest),
|
|
_haveData(haveData)
|
|
{
|
|
}
|
|
|
|
|
|
ApacheStreamBuf::~ApacheStreamBuf()
|
|
{
|
|
}
|
|
|
|
|
|
int ApacheStreamBuf::readFromDevice(char* buffer, std::streamsize len)
|
|
{
|
|
if (_haveData)
|
|
return _pApacheRequest->readRequest(buffer, static_cast<int>(len));
|
|
else
|
|
return 0;
|
|
}
|
|
|
|
|
|
int ApacheStreamBuf::writeToDevice(const char* buffer, std::streamsize length)
|
|
{
|
|
_pApacheRequest->writeResponse(buffer, length);
|
|
return length;
|
|
}
|
|
|
|
|
|
//
|
|
// ApacheIOS
|
|
//
|
|
|
|
|
|
ApacheIOS::ApacheIOS(ApacheRequestRec* pApacheRequest, bool haveData):
|
|
_buf(pApacheRequest, haveData)
|
|
{
|
|
poco_ios_init(&_buf);
|
|
}
|
|
|
|
|
|
ApacheIOS::~ApacheIOS()
|
|
{
|
|
try
|
|
{
|
|
_buf.sync();
|
|
}
|
|
catch (...)
|
|
{
|
|
}
|
|
}
|
|
|
|
|
|
ApacheStreamBuf* ApacheIOS::rdbuf()
|
|
{
|
|
return &_buf;
|
|
}
|
|
|
|
|
|
void ApacheIOS::close()
|
|
{
|
|
_buf.sync();
|
|
}
|
|
|
|
|
|
//
|
|
// ApacheOutputStream
|
|
//
|
|
|
|
|
|
ApacheOutputStream::ApacheOutputStream(ApacheRequestRec* pApacheRequest):
|
|
ApacheIOS(pApacheRequest),
|
|
std::ostream(&_buf)
|
|
{
|
|
}
|
|
|
|
|
|
ApacheOutputStream::~ApacheOutputStream()
|
|
{
|
|
}
|
|
|
|
|
|
//
|
|
// ApacheInputStream
|
|
//
|
|
|
|
|
|
ApacheInputStream::ApacheInputStream(ApacheRequestRec* pApacheRequest):
|
|
ApacheIOS(pApacheRequest, pApacheRequest->haveRequestBody()),
|
|
std::istream(&_buf)
|
|
{
|
|
}
|
|
|
|
|
|
ApacheInputStream::~ApacheInputStream()
|
|
{
|
|
}
|