Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / native_client_sdk / src / libraries / nacl_io / socket / packet.cc
blob69a894f64f14a6bb29c7ec1f8d5362f4a649639f
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
3 // found in the LICENSE file.
5 #include "nacl_io/socket/packet.h"
7 #include <assert.h>
8 #include <string.h>
10 #include "nacl_io/pepper_interface.h"
12 namespace nacl_io {
14 Packet::Packet(PepperInterface* ppapi)
15 : ppapi_(ppapi), addr_(0), buffer_(NULL), len_(0) {
18 Packet::~Packet() {
19 if ((NULL != ppapi_) && addr_)
20 ppapi_->ReleaseResource(addr_);
21 free(buffer_);
24 void Packet::Copy(const void* buffer, size_t len, PP_Resource addr) {
25 addr_ = addr;
26 len_ = len;
27 buffer_ = (char*)malloc(len);
28 assert(buffer_);
30 memcpy(buffer_, buffer, len);
31 if (addr && (NULL != ppapi_))
32 ppapi_->AddRefResource(addr);
35 } // namespace nacl_io