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

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

Issue 23498015: [NaCl SDK] Support non blocking TCP/UDP (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added Fifo Tests 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 #ifndef LIBRARIES_NACL_IO_FIFO_PACKET_H_
6 #define LIBRARIES_NACL_IO_FIFO_PACKET_H_
7
8 #include <string.h>
9
10 #include <list>
11 #include <vector>
12
13 #include "nacl_io/fifo_interface.h"
14 #include "ppapi/c/pp_resource.h"
15
16 #include "sdk_util/macros.h"
17
18 namespace nacl_io {
19
20 struct Packet {
21 Packet(const void *buffer, size_t len, PP_Resource addr)
22 : addr_(addr),
23 buffer_(len) {
24 memcpy(buffer_.data(), buffer, len);
25 }
26
27 PP_Resource addr_;
28 std::vector<char> buffer_;
29
30 DISALLOW_COPY_AND_ASSIGN(Packet);
31 };
32
33
34 // FIFOPacket
35 //
36 // A FIFOPackiet is linked list of packets. Data is stored and returned
37 // in packet size increments. FIFOPacket signals EMPTY where there are
38 // no packets, and FULL when the total bytes of all packets meets or
39 // exceeds the max size hint.
40 class FIFOPacket : public FIFOInterface {
41 public:
42 explicit FIFOPacket(size_t size);
43 virtual ~FIFOPacket();
44
45 virtual bool IsEmpty();
46 virtual bool IsFull();
47 virtual bool Resize(size_t len);
48
49 size_t ReadAvailable();
50 size_t WriteAvailable();
51
52 // Return a pointer to the top packet without releasing ownership.
53 Packet* PeekPacket();
54
55 // Relinquish top packet, and remove it from the FIFO.
56 Packet* ReadPacket();
57
58 // Take ownership of packet and place it in the FIFO.
59 void WritePacket(Packet* packet);
60
61 private:
62 std::list<Packet*> packets_;
63 uint32_t max_bytes_;
64 uint32_t cur_bytes_;
65
66 DISALLOW_COPY_AND_ASSIGN(FIFOPacket);
67 };
68
69 } // namespace nacl_io
70
71 #endif // LIBRARIES_NACL_IO_FIFO_PACKET_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698