PageRenderTime 92ms CodeModel.GetById 77ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llmessage/lliobuffer.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 114 lines | 72 code | 10 blank | 32 comment | 9 complexity | 3d3876ef214fb3c7dd49de228647d78d MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file lliobuffer.cpp
  3. * @author Phoenix
  4. * @date 2005-05-04
  5. * @brief Definition of buffer based implementations of IO Pipes.
  6. *
  7. * $LicenseInfo:firstyear=2005&license=viewerlgpl$
  8. * Second Life Viewer Source Code
  9. * Copyright (C) 2010, Linden Research, Inc.
  10. *
  11. * This library is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU Lesser General Public
  13. * License as published by the Free Software Foundation;
  14. * version 2.1 of the License only.
  15. *
  16. * This library is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  19. * Lesser General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Lesser General Public
  22. * License along with this library; if not, write to the Free Software
  23. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  24. *
  25. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  26. * $/LicenseInfo$
  27. */
  28. #include "linden_common.h"
  29. #include "lliobuffer.h"
  30. //
  31. // LLIOBuffer
  32. //
  33. LLIOBuffer::LLIOBuffer() :
  34. mBuffer(NULL),
  35. mBufferSize(0L),
  36. mReadHead(NULL),
  37. mWriteHead(NULL)
  38. {
  39. }
  40. LLIOBuffer::~LLIOBuffer()
  41. {
  42. if(mBuffer)
  43. {
  44. delete[] mBuffer;
  45. }
  46. }
  47. U8* LLIOBuffer::data() const
  48. {
  49. return mBuffer;
  50. }
  51. S64 LLIOBuffer::size() const
  52. {
  53. return mBufferSize;
  54. }
  55. U8* LLIOBuffer::current() const
  56. {
  57. return mReadHead;
  58. }
  59. S64 LLIOBuffer::bytesLeft() const
  60. {
  61. return mWriteHead - mReadHead;
  62. }
  63. void LLIOBuffer::clear()
  64. {
  65. mReadHead = mBuffer;
  66. mWriteHead = mBuffer;
  67. }
  68. LLIOPipe::EStatus LLIOBuffer::seek(LLIOBuffer::EHead head, S64 delta)
  69. {
  70. LLIOPipe::EStatus status = STATUS_ERROR;
  71. switch(head)
  72. {
  73. case READ:
  74. if(((delta >= 0) && ((mReadHead + delta) <= mWriteHead))
  75. || ((delta < 0) && ((mReadHead + delta) >= mBuffer)))
  76. {
  77. mReadHead += delta;
  78. status = STATUS_OK;
  79. }
  80. break;
  81. case WRITE:
  82. if(((delta >= 0) && ((mWriteHead + delta) < (mBuffer + mBufferSize)))
  83. || ((delta < 0) && ((mWriteHead + delta) > mReadHead)))
  84. {
  85. mWriteHead += delta;
  86. status = STATUS_OK;
  87. }
  88. default:
  89. break;
  90. }
  91. return status;
  92. }
  93. // virtual
  94. LLIOPipe::EStatus LLIOBuffer::process_impl(
  95. const LLChannelDescriptors& channels,
  96. buffer_ptr_t& buffer,
  97. bool& eos,
  98. LLSD& context,
  99. LLPumpIO* pump)
  100. {
  101. // no-op (I think)
  102. llwarns << "You are using an LLIOBuffer which is deprecated." << llendl;
  103. return STATUS_OK;
  104. }