Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(585)

Side by Side Diff: native_client_sdk/src/libraries/nacl_io/socket/tcp_node.cc

Issue 443693002: [NaCl SDK] nacl_io: Remove use of new/delete for data buffers. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/ossocket.h" 5 #include "nacl_io/ossocket.h"
6 #ifdef PROVIDES_SOCKET_API 6 #ifdef PROVIDES_SOCKET_API
7 7
8 #include <assert.h> 8 #include <assert.h>
9 #include <errno.h> 9 #include <errno.h>
10 #include <string.h> 10 #include <string.h>
(...skipping 12 matching lines...) Expand all
23 23
24 namespace nacl_io { 24 namespace nacl_io {
25 25
26 class TcpWork : public StreamFs::Work { 26 class TcpWork : public StreamFs::Work {
27 public: 27 public:
28 explicit TcpWork(const ScopedTcpEventEmitter& emitter) 28 explicit TcpWork(const ScopedTcpEventEmitter& emitter)
29 : StreamFs::Work(emitter->stream()->stream()), 29 : StreamFs::Work(emitter->stream()->stream()),
30 emitter_(emitter), 30 emitter_(emitter),
31 data_(NULL) {} 31 data_(NULL) {}
32 32
33 ~TcpWork() { delete[] data_; } 33 ~TcpWork() {
34 free(data_);
35 }
34 36
35 TCPSocketInterface* TCPInterface() { 37 TCPSocketInterface* TCPInterface() {
36 return filesystem()->ppapi()->GetTCPSocketInterface(); 38 return filesystem()->ppapi()->GetTCPSocketInterface();
37 } 39 }
38 40
39 protected: 41 protected:
40 ScopedTcpEventEmitter emitter_; 42 ScopedTcpEventEmitter emitter_;
41 char* data_; 43 char* data_;
42 }; 44 };
43 45
(...skipping 12 matching lines...) Expand all
56 58
57 // Check if we are already sending. 59 // Check if we are already sending.
58 if (node_->TestStreamFlags(SSF_SENDING)) 60 if (node_->TestStreamFlags(SSF_SENDING))
59 return false; 61 return false;
60 62
61 size_t tx_data_avail = emitter_->BytesInOutputFIFO(); 63 size_t tx_data_avail = emitter_->BytesInOutputFIFO();
62 int capped_len = std::min(tx_data_avail, kMaxPacketSize); 64 int capped_len = std::min(tx_data_avail, kMaxPacketSize);
63 if (capped_len == 0) 65 if (capped_len == 0)
64 return false; 66 return false;
65 67
66 data_ = new char[capped_len]; 68 data_ = (char*)malloc(capped_len);
69 assert(data_);
70 if (data_ == NULL)
71 return false;
67 emitter_->ReadOut_Locked(data_, capped_len); 72 emitter_->ReadOut_Locked(data_, capped_len);
68 73
69 int err = TCPInterface()->Write(node_->socket_resource(), 74 int err = TCPInterface()->Write(node_->socket_resource(),
70 data_, 75 data_,
71 capped_len, 76 capped_len,
72 filesystem()->GetRunCompletion(this)); 77 filesystem()->GetRunCompletion(this));
73 78
74 if (err != PP_OK_COMPLETIONPENDING) { 79 if (err != PP_OK_COMPLETIONPENDING) {
75 // Anything else, we should assume the socket has gone bad. 80 // Anything else, we should assume the socket has gone bad.
76 node_->SetError_Locked(err); 81 node_->SetError_Locked(err);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 if (stream->TestStreamFlags(SSF_RECVING)) 124 if (stream->TestStreamFlags(SSF_RECVING))
120 return false; 125 return false;
121 126
122 size_t rx_space_avail = emitter_->SpaceInInputFIFO(); 127 size_t rx_space_avail = emitter_->SpaceInInputFIFO();
123 int capped_len = 128 int capped_len =
124 static_cast<int32_t>(std::min(rx_space_avail, kMaxPacketSize)); 129 static_cast<int32_t>(std::min(rx_space_avail, kMaxPacketSize));
125 130
126 if (capped_len == 0) 131 if (capped_len == 0)
127 return false; 132 return false;
128 133
129 data_ = new char[capped_len]; 134 data_ = (char*)malloc(capped_len);
135 assert(data_);
136 if (data_ == NULL)
137 return false;
130 int err = TCPInterface()->Read(stream->socket_resource(), 138 int err = TCPInterface()->Read(stream->socket_resource(),
131 data_, 139 data_,
132 capped_len, 140 capped_len,
133 filesystem()->GetRunCompletion(this)); 141 filesystem()->GetRunCompletion(this));
134 if (err != PP_OK_COMPLETIONPENDING) { 142 if (err != PP_OK_COMPLETIONPENDING) {
135 // Anything else, we should assume the socket has gone bad. 143 // Anything else, we should assume the socket has gone bad.
136 stream->SetError_Locked(err); 144 stream->SetError_Locked(err);
137 return false; 145 return false;
138 } 146 }
139 147
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after
556 assert(emitter_.get()); 564 assert(emitter_.get());
557 if (emitter_->GetError_Locked()) 565 if (emitter_->GetError_Locked())
558 return EPIPE; 566 return EPIPE;
559 *out_len = emitter_->WriteOut_Locked((char*)buf, len); 567 *out_len = emitter_->WriteOut_Locked((char*)buf, len);
560 return 0; 568 return 0;
561 } 569 }
562 570
563 } // namespace nacl_io 571 } // namespace nacl_io
564 572
565 #endif // PROVIDES_SOCKET_API 573 #endif // PROVIDES_SOCKET_API
OLDNEW
« no previous file with comments | « native_client_sdk/src/libraries/nacl_io/socket/packet.cc ('k') | native_client_sdk/src/libraries/nacl_io/socket/udp_node.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698