diff options
author | Devtools Arcadia <arcadia-devtools@yandex-team.ru> | 2022-02-07 18:08:42 +0300 |
---|---|---|
committer | Devtools Arcadia <arcadia-devtools@mous.vla.yp-c.yandex.net> | 2022-02-07 18:08:42 +0300 |
commit | 1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch) | |
tree | e26c9fed0de5d9873cce7e00bc214573dc2195b7 /contrib/libs/poco/Net/src/SocketStream.cpp | |
download | ydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz |
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'contrib/libs/poco/Net/src/SocketStream.cpp')
-rw-r--r-- | contrib/libs/poco/Net/src/SocketStream.cpp | 156 |
1 files changed, 156 insertions, 0 deletions
diff --git a/contrib/libs/poco/Net/src/SocketStream.cpp b/contrib/libs/poco/Net/src/SocketStream.cpp new file mode 100644 index 0000000000..77ae8c2442 --- /dev/null +++ b/contrib/libs/poco/Net/src/SocketStream.cpp @@ -0,0 +1,156 @@ +// +// SocketStream.cpp +// +// Library: Net +// Package: Sockets +// Module: SocketStream +// +// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// SPDX-License-Identifier: BSL-1.0 +// + + +#include "Poco/Net/SocketStream.h" +#include "Poco/Net/StreamSocketImpl.h" +#include "Poco/Exception.h" + + +using Poco::BufferedBidirectionalStreamBuf; +using Poco::InvalidArgumentException; + + +namespace Poco { +namespace Net { + + +// +// SocketStreamBuf +// + + +SocketStreamBuf::SocketStreamBuf(const Socket& socket): + BufferedBidirectionalStreamBuf(STREAM_BUFFER_SIZE, std::ios::in | std::ios::out), + _pImpl(dynamic_cast<StreamSocketImpl*>(socket.impl())) +{ + if (_pImpl) + _pImpl->duplicate(); + else + throw InvalidArgumentException("Invalid or null SocketImpl passed to SocketStreamBuf"); +} + + +SocketStreamBuf::~SocketStreamBuf() +{ + _pImpl->release(); +} + + +int SocketStreamBuf::readFromDevice(char* buffer, std::streamsize length) +{ + return _pImpl->receiveBytes(buffer, (int) length); +} + + +int SocketStreamBuf::writeToDevice(const char* buffer, std::streamsize length) +{ + return _pImpl->sendBytes(buffer, (int) length); +} + + +// +// SocketIOS +// + + +SocketIOS::SocketIOS(const Socket& socket): + _buf(socket) +{ + poco_ios_init(&_buf); +} + + +SocketIOS::~SocketIOS() +{ + try + { + _buf.sync(); + } + catch (...) + { + } +} + + +SocketStreamBuf* SocketIOS::rdbuf() +{ + return &_buf; +} + + +void SocketIOS::close() +{ + _buf.sync(); + _buf.socketImpl()->close(); +} + + +StreamSocket SocketIOS::socket() const +{ + return StreamSocket(_buf.socketImpl()); +} + + +// +// SocketOutputStream +// + + +SocketOutputStream::SocketOutputStream(const Socket& socket): + SocketIOS(socket), + std::ostream(&_buf) +{ +} + + +SocketOutputStream::~SocketOutputStream() +{ +} + + +// +// SocketInputStream +// + + +SocketInputStream::SocketInputStream(const Socket& socket): + SocketIOS(socket), + std::istream(&_buf) +{ +} + + +SocketInputStream::~SocketInputStream() +{ +} + + +// +// SocketStream +// + + +SocketStream::SocketStream(const Socket& socket): + SocketIOS(socket), + std::iostream(&_buf) +{ +} + + +SocketStream::~SocketStream() +{ +} + + +} } // namespace Poco::Net |