58BinaryOSocket::BinaryOSocket(
size_t bufferSize,
unsigned long flushPeriod):
61 requestedBufferSize_(bufferSize),
63 flushPeriod_(flushPeriod),
64 stopFlushThread_(false),
76BinaryOSocket::BinaryOSocket(
Socket* socket,
size_t bufferSize,
unsigned long flushPeriod):
79 requestedBufferSize_(bufferSize),
81 flushPeriod_(flushPeriod),
82 stopFlushThread_(false),
90BinaryOSocket::~BinaryOSocket()
92 stopFlushThread_ =
true;
100 flushCondition_.signal();
101 flushThread_->join();
103 catch (std::exception& error)
105 std::cerr <<
"[LASS RUN MSG] UNDEFINED BEHAVIOUR WARNING: exception thrown in ~BinaryOSocket(): " << error.what() << std::endl;
109 std::cerr <<
"[LASS RUN MSG] UNDEFINED BEHAVIOUR WARNING: unknown exception thrown in ~BinaryOSocket()" << std::endl;
115Socket* BinaryOSocket::socket()
const
140BinaryOSocket::pos_type BinaryOSocket::doTellp()
const
142 LASS_THROW(
"no position in network streams");
147void BinaryOSocket::doSeekp(pos_type)
149 LASS_THROW(
"no seeking in network streams");
154void BinaryOSocket::doSeekp(off_type, std::ios_base::seekdir)
156 LASS_THROW(
"no seeking in network streams");
161void BinaryOSocket::doFlush()
175size_t BinaryOSocket::doWrite(
const void* begin,
size_t numberOfBytes)
181 setstate(std::ios_base::badbit);
184 const char* first =
static_cast<const char*
>(begin);
185 size_t bytesToWrite = numberOfBytes;
186 while (bytesToWrite > 0)
188 if (current_ == buffer_.size())
198 LASS_ASSERT(current_ < buffer_.size());
199 const size_t freeSize = buffer_.size() - current_;
200 const size_t writeSize = std::min(bytesToWrite, freeSize);
202 ::memcpy(&buffer_[current_], first, writeSize);
203 current_ += writeSize;
205 bytesToWrite -= writeSize;
210 return numberOfBytes;
215void BinaryOSocket::init()
217 size_t size = requestedBufferSize_;
220 const size_t maxSize = num::numCast<size_t>(socket_->sizeSendBuffer());
223 size = std::min(size, maxSize);
230 buffer_.resize(size);
242void BinaryOSocket::flusher()
244 while (!stopFlushThread_)
246 LASS_TRY_LOCK( bufferLock_ )
254 flushCondition_.wait(flushPeriod_);
259void BinaryOSocket::flushImpl()
261 if (!good() || !socket_ || buffer_.empty())
266 const char* begin = &buffer_[0];
267 const size_t nMax =
static_cast<size_t>(num::NumTraits<int>::max);
271 const int n =
static_cast<int>(current_ > nMax ? nMax : current_);
272 LASS_ASSERT(n > 0 &&
static_cast<size_t>(n) <= current_);
275 const int sent = socket_->send(begin, n);
276 LASS_ASSERT(sent >= 0 && sent <= n);
278 current_ -=
static_cast<size_t>(sent);
280 catch (
const util::Exception&)
282 setstate(std::ios_base::badbit);
void setSocket(Socket *socket)
base class of binary output streams.
#define LASS_LOCK(iLock)
Locks a iLock and starts a scope block in which it remains locked.
@ threadJoinable
joinable thread, can be waited for
streams, binary streams, vrmlstreams, ...
Library for Assembled Shared Sources.