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 #include "nacl_io/socket/fifo_packet.h"
12 #include "nacl_io/socket/packet.h"
16 FIFOPacket::FIFOPacket(size_t size
) : max_bytes_(size
), cur_bytes_(0) {
19 FIFOPacket::~FIFOPacket() {
24 bool FIFOPacket::IsEmpty() {
25 return packets_
.empty();
28 bool FIFOPacket::Resize(size_t len
) {
33 size_t FIFOPacket::ReadAvailable() {
37 size_t FIFOPacket::WriteAvailable() {
38 if (cur_bytes_
> max_bytes_
)
41 return max_bytes_
- cur_bytes_
;
44 bool FIFOPacket::IsFull() {
45 return cur_bytes_
>= max_bytes_
;
48 Packet
* FIFOPacket::PeekPacket() {
52 return packets_
.back();
55 Packet
* FIFOPacket::ReadPacket() {
59 Packet
* out
= packets_
.back();
62 cur_bytes_
-= out
->len();
66 void FIFOPacket::WritePacket(Packet
* packet
) {
67 cur_bytes_
+= packet
->len();
68 packets_
.push_front(packet
);
71 } // namespace nacl_io