Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / native_client_sdk / src / libraries / nacl_io / socket / fifo_packet.h
blobe8ba0b3c38423237b694f48c92e6c489cd534d0b
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef LIBRARIES_NACL_IO_FIFO_PACKET_H_
6 #define LIBRARIES_NACL_IO_FIFO_PACKET_H_
8 #include <string.h>
10 #include <list>
12 #include "nacl_io/fifo_interface.h"
13 #include "ppapi/c/pp_resource.h"
15 #include "sdk_util/macros.h"
17 namespace nacl_io {
19 class Packet;
21 // FIFOPacket
23 // A FIFOPackiet is linked list of packets. Data is stored and returned
24 // in packet size increments. FIFOPacket signals EMPTY where there are
25 // no packets, and FULL when the total bytes of all packets meets or
26 // exceeds the max size hint.
27 class FIFOPacket : public FIFOInterface {
28 public:
29 explicit FIFOPacket(size_t size);
30 virtual ~FIFOPacket();
32 virtual bool IsEmpty();
33 virtual bool IsFull();
34 virtual bool Resize(size_t len);
36 size_t ReadAvailable();
37 size_t WriteAvailable();
39 // Return a pointer to the top packet without releasing ownership.
40 Packet* PeekPacket();
42 // Relinquish top packet, and remove it from the FIFO.
43 Packet* ReadPacket();
45 // Take ownership of packet and place it in the FIFO.
46 void WritePacket(Packet* packet);
48 private:
49 std::list<Packet*> packets_;
50 uint32_t max_bytes_;
51 uint32_t cur_bytes_;
53 DISALLOW_COPY_AND_ASSIGN(FIFOPacket);
56 } // namespace nacl_io
58 #endif // LIBRARIES_NACL_IO_FIFO_PACKET_H_