| Index: native_client_sdk/src/libraries/nacl_io/fifo_packet.h
|
| diff --git a/native_client_sdk/src/libraries/nacl_io/fifo_packet.h b/native_client_sdk/src/libraries/nacl_io/fifo_packet.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..1b6286bf627a63cfb7b1361179ea5292c361daba
|
| --- /dev/null
|
| +++ b/native_client_sdk/src/libraries/nacl_io/fifo_packet.h
|
| @@ -0,0 +1,66 @@
|
| +// Copyright (c) 2013 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#ifndef LIBRARIES_NACL_IO_FIFO_PACKET_H_
|
| +#define LIBRARIES_NACL_IO_FIFO_PACKET_H_
|
| +
|
| +#include <stdint.h>
|
| +#include <stdlib.h>
|
| +#include <string.h>
|
| +
|
| +#include <list>
|
| +
|
| +#include "nacl_io/fifo_interface.h"
|
| +#include "ppapi/c/pp_resource.h"
|
| +
|
| +namespace nacl_io {
|
| +
|
| +struct Packet {
|
| + Packet(const char *buffer, int32_t len, PP_Resource addr)
|
| + : len_(len),
|
| + addr_(addr) {
|
| + buffer_ = new char[len];
|
| + memcpy(buffer_, buffer, len);
|
| + }
|
| +
|
| + ~Packet() {
|
| + delete[] buffer_;
|
| + }
|
| +
|
| + char* buffer_;
|
| + int32_t len_;
|
| + PP_Resource addr_;
|
| +};
|
| +
|
| +class FIFOPacket {
|
| + public:
|
| + explicit FIFOPacket(size_t size);
|
| + ~FIFOPacket();
|
| +
|
| + virtual bool IsEmpty();
|
| + virtual bool IsFull();
|
| + virtual bool Resize(size_t len);
|
| +
|
| + // Reads out no more than the requested len without updating the tail.
|
| + // Returns actual amount read.
|
| + Packet* PeekPacket();
|
| +
|
| + // Reads out the data making room in the FIFO. Returns actual amount
|
| + // read.
|
| + Packet* ReadPacket();
|
| +
|
| + // Writes into the FIFO no more than len bytes, returns actual amount
|
| + // written.
|
| + uint32_t WritePacket(Packet* packet);
|
| +
|
| +
|
| +private:
|
| + std::list<UDPPacket*> packets_;
|
| + uint32_t max_bytes_;
|
| + uint32_t cur_bytes_;
|
| +};
|
| +
|
| +} // namespace nacl_io
|
| +
|
| +#endif // LIBRARIES_NACL_IO_FIFO_PACKET_H_
|
|
|