ozone: evdev: Sync caps lock LED state to evdev
[chromium-blink-merge.git] / native_client_sdk / src / libraries / nacl_io / socket / fifo_packet.cc
blob3e5c330b52f35babbe5ffd7a5ccf38da6e06b953
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"
7 #include <stdlib.h>
8 #include <string.h>
10 #include <algorithm>
12 #include "nacl_io/socket/packet.h"
14 namespace nacl_io {
16 FIFOPacket::FIFOPacket(size_t size) : max_bytes_(size), cur_bytes_(0) {
19 FIFOPacket::~FIFOPacket() {
20 while (!IsEmpty())
21 delete ReadPacket();
24 bool FIFOPacket::IsEmpty() {
25 return packets_.empty();
28 bool FIFOPacket::Resize(size_t len) {
29 max_bytes_ = len;
30 return true;
33 size_t FIFOPacket::ReadAvailable() {
34 return cur_bytes_;
37 size_t FIFOPacket::WriteAvailable() {
38 if (cur_bytes_ > max_bytes_)
39 return 0;
41 return max_bytes_ - cur_bytes_;
44 bool FIFOPacket::IsFull() {
45 return cur_bytes_ >= max_bytes_;
48 Packet* FIFOPacket::PeekPacket() {
49 if (packets_.empty())
50 return NULL;
52 return packets_.back();
55 Packet* FIFOPacket::ReadPacket() {
56 if (packets_.empty())
57 return NULL;
59 Packet* out = packets_.back();
60 packets_.pop_back();
62 cur_bytes_ -= out->len();
63 return out;
66 void FIFOPacket::WritePacket(Packet* packet) {
67 cur_bytes_ += packet->len();
68 packets_.push_front(packet);
71 } // namespace nacl_io