PageRenderTime 45ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/mordor/streams/test.cpp

http://github.com/mozy/mordor
C++ | 58 lines | 50 code | 7 blank | 1 comment | 17 complexity | 5685601cd8657ddb52d84d2225a47f66 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. // Copyright (c) 2009 - Mozy, Inc.
  2. #include "test.h"
  3. namespace Mordor {
  4. void
  5. TestStream::close(CloseType type)
  6. {
  7. if (m_onClose)
  8. m_onClose(type);
  9. if (ownsParent())
  10. parent()->close(type);
  11. }
  12. size_t
  13. TestStream::read(Buffer &b, size_t len)
  14. {
  15. len = (std::min)(len, m_maxReadSize);
  16. if (m_onRead) {
  17. if (m_onReadBytes == 0) {
  18. m_onRead();
  19. }
  20. }
  21. if (m_onRead && m_onReadBytes > 0)
  22. len = (size_t)std::min<long long>(len, m_onReadBytes);
  23. size_t result = parent()->read(b, len);
  24. if (m_onRead && m_onReadBytes > 0)
  25. m_onReadBytes -= result;
  26. return result;
  27. }
  28. size_t
  29. TestStream::write(const Buffer &b, size_t len)
  30. {
  31. len = (std::min)(len, m_maxWriteSize);
  32. if (m_onWrite) {
  33. if (m_onWriteBytes == 0) {
  34. m_onWrite();
  35. }
  36. }
  37. if (m_onWrite && m_onWriteBytes > 0)
  38. len = (size_t)std::min<long long>(len, m_onWriteBytes);
  39. size_t result = parent()->write(b, len);
  40. if (m_onWrite && m_onWriteBytes > 0)
  41. m_onWriteBytes -= result;
  42. return result;
  43. }
  44. void
  45. TestStream::flush(bool flushParent)
  46. {
  47. if (m_onFlush)
  48. m_onFlush(flushParent);
  49. parent()->flush(flushParent);
  50. }
  51. }