| OLD | NEW |
| (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 <stdint.h> |
| 9 #include <stdlib.h> |
| 10 #include <string.h> |
| 11 |
| 12 #include <list> |
| 13 |
| 14 #include "nacl_io/fifo_interface.h" |
| 15 #include "ppapi/c/pp_resource.h" |
| 16 |
| 17 namespace nacl_io { |
| 18 |
| 19 struct Packet { |
| 20 Packet(const char *buffer, int32_t len, PP_Resource addr) |
| 21 : len_(len), |
| 22 addr_(addr) { |
| 23 buffer_ = new char[len]; |
| 24 memcpy(buffer_, buffer, len); |
| 25 } |
| 26 |
| 27 ~Packet() { |
| 28 delete[] buffer_; |
| 29 } |
| 30 |
| 31 char* buffer_; |
| 32 int32_t len_; |
| 33 PP_Resource addr_; |
| 34 }; |
| 35 |
| 36 class FIFOPacket { |
| 37 public: |
| 38 explicit FIFOPacket(size_t size); |
| 39 ~FIFOPacket(); |
| 40 |
| 41 virtual bool IsEmpty(); |
| 42 virtual bool IsFull(); |
| 43 virtual bool Resize(size_t len); |
| 44 |
| 45 // Reads out no more than the requested len without updating the tail. |
| 46 // Returns actual amount read. |
| 47 Packet* PeekPacket(); |
| 48 |
| 49 // Reads out the data making room in the FIFO. Returns actual amount |
| 50 // read. |
| 51 Packet* ReadPacket(); |
| 52 |
| 53 // Writes into the FIFO no more than len bytes, returns actual amount |
| 54 // written. |
| 55 uint32_t WritePacket(Packet* packet); |
| 56 |
| 57 |
| 58 private: |
| 59 std::list<UDPPacket*> packets_; |
| 60 uint32_t max_bytes_; |
| 61 uint32_t cur_bytes_; |
| 62 }; |
| 63 |
| 64 } // namespace nacl_io |
| 65 |
| 66 #endif // LIBRARIES_NACL_IO_FIFO_PACKET_H_ |
| OLD | NEW |