| 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 #include "nacl_io/packet.h" |
| 6 |
| 7 #include <string.h> |
| 8 |
| 9 #include "nacl_io/pepper_interface.h" |
| 10 |
| 11 namespace nacl_io { |
| 12 |
| 13 Packet::Packet(PepperInterface* ppapi) |
| 14 : ppapi_(ppapi), |
| 15 addr_(0), |
| 16 buffer_(NULL), |
| 17 len_(0) {} |
| 18 |
| 19 Packet:: ~Packet() { |
| 20 if ((NULL != ppapi_) && addr_) |
| 21 ppapi_->ReleaseResource(addr_); |
| 22 delete[] buffer_; |
| 23 } |
| 24 |
| 25 void Packet::Take(const void *buffer, size_t len, PP_Resource addr) { |
| 26 addr_ = addr; |
| 27 len_ = len; |
| 28 buffer_ = static_cast<char*>(const_cast<void*>(buffer)); |
| 29 } |
| 30 |
| 31 void Packet::Copy(const void *buffer, size_t len, PP_Resource addr) { |
| 32 addr_ = addr; |
| 33 len_ = len; |
| 34 buffer_ = new char[len]; |
| 35 |
| 36 memcpy(buffer_, buffer, len); |
| 37 if (addr && (NULL != ppapi_)) |
| 38 ppapi_->AddRefResource(addr); |
| 39 } |
| 40 |
| 41 } // namespace nacl_io |
| OLD | NEW |