Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/netwerk/base/SimpleBuffer.h
Line
Count
Source (jump to first uncovered line)
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/. */
6
7
#ifndef SimpleBuffer_h__
8
#define SimpleBuffer_h__
9
10
/*
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.
14
*/
15
16
#include "prtypes.h"
17
#include "mozilla/LinkedList.h"
18
#include "nsIThreadInternal.h"
19
20
namespace mozilla {
21
namespace net {
22
23
class SimpleBufferPage : public LinkedListElement<SimpleBufferPage>
24
{
25
public:
26
0
  SimpleBufferPage() : mReadOffset(0), mWriteOffset(0) {}
27
  static const size_t kSimpleBufferPageSize = 32000;
28
29
private:
30
  friend class SimpleBuffer;
31
  char mBuffer[kSimpleBufferPageSize];
32
  size_t mReadOffset;
33
  size_t mWriteOffset;
34
};
35
36
class SimpleBuffer
37
{
38
public:
39
  SimpleBuffer();
40
0
  ~SimpleBuffer() = default;
41
42
  nsresult Write(char *stc, size_t len); // return OK or OUT_OF_MEMORY
43
  size_t Read(char *dest, size_t maxLen); // return bytes read
44
  size_t Available();
45
  void Clear();
46
47
private:
48
  NS_DECL_OWNINGTHREAD
49
50
  nsresult mStatus;
51
  AutoCleanLinkedList<SimpleBufferPage> mBufferList;
52
  size_t mAvailable;
53
};
54
55
} // namespace net
56
} // namespace mozilla
57
58
#endif