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

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: Remove event friends, rename EventListenerPoll 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 namespace nacl_io {
13
14 FIFOPacket::FIFOPacket(size_t size)
15 : max_bytes_(size),
16 cur_bytes_(0) {}
17
18 FIFOPacket::~FIFOPacket() {
19 while (!IsEmpty())
20 delete Read();
21 }
22
23 bool FIFOPacket::IsEmpty() {
24 return packets_.empty();
25 }
26
27 bool FIFOPacket::Resize(size_t len) {
28 max_bytes_ = len;
29 return true;
binji 2013/09/12 01:47:57 why always return true here? What if len < cur_byt
noelallen1 2013/09/12 23:19:03 For Packet FIFOs, the requested size is a hint so
30 }
31
32 bool FIFOPacket::IsFull() {
33 return cur_bytes_ >= max_bytes_;
34 }
35
36 UDPPacket* FIFOPacket::Peek() {
37 if (packets_.empty())
38 return NULL;
39
40 return packets_.back();
41 }
42
43 UDPPacket* FIFOPacket::Read() {
44 if (packets_.empty())
45 return NULL;
46
47 UDPPacket* out = packets_.back();
48 packets_.pop_back();
49
50 cur_bytes_ -= out->len_;
51 return out;
52 }
53
54 void FIFOPacket::Write(UDPPacket* packet) {
55 cur_bytes_ += packet->len_;
56 packets_.push_front(packet);
57 }
58
59 } // namespace nacl_io
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698