| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "nacl_io/socket/packet.h" | 5 #include "nacl_io/socket/packet.h" |
| 6 | 6 |
| 7 #include <string.h> | 7 #include <string.h> |
| 8 | 8 |
| 9 #include "nacl_io/pepper_interface.h" | 9 #include "nacl_io/pepper_interface.h" |
| 10 | 10 |
| 11 namespace nacl_io { | 11 namespace nacl_io { |
| 12 | 12 |
| 13 Packet::Packet(PepperInterface* ppapi) | 13 Packet::Packet(PepperInterface* ppapi) |
| 14 : ppapi_(ppapi), addr_(0), buffer_(NULL), len_(0) {} | 14 : ppapi_(ppapi), addr_(0), buffer_(NULL), len_(0) { |
| 15 } |
| 15 | 16 |
| 16 Packet::~Packet() { | 17 Packet::~Packet() { |
| 17 if ((NULL != ppapi_) && addr_) | 18 if ((NULL != ppapi_) && addr_) |
| 18 ppapi_->ReleaseResource(addr_); | 19 ppapi_->ReleaseResource(addr_); |
| 19 delete[] buffer_; | 20 delete[] buffer_; |
| 20 } | 21 } |
| 21 | 22 |
| 22 void Packet::Take(const void* buffer, size_t len, PP_Resource addr) { | 23 void Packet::Take(const void* buffer, size_t len, PP_Resource addr) { |
| 23 addr_ = addr; | 24 addr_ = addr; |
| 24 len_ = len; | 25 len_ = len; |
| 25 buffer_ = static_cast<char*>(const_cast<void*>(buffer)); | 26 buffer_ = static_cast<char*>(const_cast<void*>(buffer)); |
| 26 } | 27 } |
| 27 | 28 |
| 28 void Packet::Copy(const void* buffer, size_t len, PP_Resource addr) { | 29 void Packet::Copy(const void* buffer, size_t len, PP_Resource addr) { |
| 29 addr_ = addr; | 30 addr_ = addr; |
| 30 len_ = len; | 31 len_ = len; |
| 31 buffer_ = new char[len]; | 32 buffer_ = new char[len]; |
| 32 | 33 |
| 33 memcpy(buffer_, buffer, len); | 34 memcpy(buffer_, buffer, len); |
| 34 if (addr && (NULL != ppapi_)) | 35 if (addr && (NULL != ppapi_)) |
| 35 ppapi_->AddRefResource(addr); | 36 ppapi_->AddRefResource(addr); |
| 36 } | 37 } |
| 37 | 38 |
| 38 } // namespace nacl_io | 39 } // namespace nacl_io |
| OLD | NEW |