Bug 1837643 [wpt PR 40475] - [RemoveLegacy] GridTrackList::legacy_track_list_, a...
[gecko.git] / netwerk / base / SimpleBuffer.h
blob031f59afe5d93738b63305cf313e4a198da56a28
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.
16 #include "prtypes.h"
17 #include "ErrorList.h"
18 #include "mozilla/LinkedList.h"
19 #include "nsISupportsImpl.h"
21 namespace mozilla {
22 namespace net {
24 class SimpleBufferPage : public LinkedListElement<SimpleBufferPage> {
25 public:
26 SimpleBufferPage() = default;
27 static const size_t kSimpleBufferPageSize = 32000;
29 private:
30 friend class SimpleBuffer;
31 char mBuffer[kSimpleBufferPageSize]{0};
32 size_t mReadOffset{0};
33 size_t mWriteOffset{0};
36 class SimpleBuffer {
37 public:
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
43 size_t Available();
44 void Clear();
46 private:
47 NS_DECL_OWNINGTHREAD
49 nsresult mStatus{NS_OK};
50 AutoCleanLinkedList<SimpleBufferPage> mBufferList;
51 size_t mAvailable{0};
54 } // namespace net
55 } // namespace mozilla
57 #endif