/mordor/streams/test.cpp
C++ | 58 lines | 50 code | 7 blank | 1 comment | 17 complexity | 5685601cd8657ddb52d84d2225a47f66 MD5 | raw file
Possible License(s): BSD-3-Clause
- // Copyright (c) 2009 - Mozy, Inc.
- #include "test.h"
- namespace Mordor {
- void
- TestStream::close(CloseType type)
- {
- if (m_onClose)
- m_onClose(type);
- if (ownsParent())
- parent()->close(type);
- }
- size_t
- TestStream::read(Buffer &b, size_t len)
- {
- len = (std::min)(len, m_maxReadSize);
- if (m_onRead) {
- if (m_onReadBytes == 0) {
- m_onRead();
- }
- }
- if (m_onRead && m_onReadBytes > 0)
- len = (size_t)std::min<long long>(len, m_onReadBytes);
- size_t result = parent()->read(b, len);
- if (m_onRead && m_onReadBytes > 0)
- m_onReadBytes -= result;
- return result;
- }
- size_t
- TestStream::write(const Buffer &b, size_t len)
- {
- len = (std::min)(len, m_maxWriteSize);
- if (m_onWrite) {
- if (m_onWriteBytes == 0) {
- m_onWrite();
- }
- }
- if (m_onWrite && m_onWriteBytes > 0)
- len = (size_t)std::min<long long>(len, m_onWriteBytes);
- size_t result = parent()->write(b, len);
- if (m_onWrite && m_onWriteBytes > 0)
- m_onWriteBytes -= result;
- return result;
- }
- void
- TestStream::flush(bool flushParent)
- {
- if (m_onFlush)
- m_onFlush(flushParent);
- parent()->flush(flushParent);
- }
- }