1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:set ts=2 sw=2 sts=2 et cindent: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef SimpleBuffer_h__
8 #define SimpleBuffer_h__
11 This class is similar to a nsPipe except it does not have any locking, stores
12 an unbounded amount of data, can only be used on one thread, and has much
13 simpler result code semantics to deal with.
17 #include "ErrorList.h"
18 #include "mozilla/LinkedList.h"
19 #include "nsISupportsImpl.h"
24 class SimpleBufferPage
: public LinkedListElement
<SimpleBufferPage
> {
26 SimpleBufferPage() = default;
27 static const size_t kSimpleBufferPageSize
= 32000;
30 friend class SimpleBuffer
;
31 char mBuffer
[kSimpleBufferPageSize
]{0};
32 size_t mReadOffset
{0};
33 size_t mWriteOffset
{0};
38 SimpleBuffer() = default;
39 ~SimpleBuffer() = default;
41 nsresult
Write(char* src
, size_t len
); // return OK or OUT_OF_MEMORY
42 size_t Read(char* dest
, size_t maxLen
); // return bytes read
49 nsresult mStatus
{NS_OK
};
50 AutoCleanLinkedList
<SimpleBufferPage
> mBufferList
;
55 } // namespace mozilla