Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(473)

Side by Side Diff: native_client_sdk/src/libraries/nacl_io/fifo_packet.cc

Issue 23498015: [NaCl SDK] Support non blocking TCP/UDP (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 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.
4
5 #include "nacl_io/fifo_packet.h"
6
7 #include <stdlib.h>
8 #include <string.h>
9
10 #include <algorithm>
11
12 #include "nacl_io/packet.h"
13
14 namespace nacl_io {
15
16 FIFOPacket::FIFOPacket(size_t size)
17 : max_bytes_(size),
18 cur_bytes_(0) {}
19
20 FIFOPacket::~FIFOPacket() {
21 while (!IsEmpty())
22 delete ReadPacket();
23 }
24
25 bool FIFOPacket::IsEmpty() {
26 return packets_.empty();
27 }
28
29 bool FIFOPacket::Resize(size_t len) {
30 max_bytes_ = len;
31 return true;
32 }
33
34 size_t FIFOPacket::ReadAvailable() {
35 return cur_bytes_;
36 }
37
38 size_t FIFOPacket::WriteAvailable() {
39 if (cur_bytes_ > max_bytes_)
40 return 0;
41
42 return max_bytes_ - cur_bytes_;
43 }
44
45 bool FIFOPacket::IsFull() {
46 return cur_bytes_ >= max_bytes_;
47 }
48
49 Packet* FIFOPacket::PeekPacket() {
50 if (packets_.empty())
51 return NULL;
52
53 return packets_.back();
54 }
55
56 Packet* FIFOPacket::ReadPacket() {
57 if (packets_.empty())
58 return NULL;
59
60 Packet* out = packets_.back();
61 packets_.pop_back();
62
63 cur_bytes_ -= out->len();
64 return out;
65 }
66
67 void FIFOPacket::WritePacket(Packet* packet) {
68 cur_bytes_ += packet->len();
69 packets_.push_front(packet);
70 }
71
72 } // namespace nacl_io
OLDNEW
« no previous file with comments | « native_client_sdk/src/libraries/nacl_io/fifo_packet.h ('k') | native_client_sdk/src/libraries/nacl_io/kernel_intercept.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698