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

Side by Side Diff: third_party/mojo/src/mojo/edk/system/raw_channel_posix.cc

Issue 1040163002: RawChannelPosix: Close handles only if they are sent successfully. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "mojo/edk/system/raw_channel.h" 5 #include "mojo/edk/system/raw_channel.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <sys/uio.h> 8 #include <sys/uio.h>
9 #include <unistd.h> 9 #include <unistd.h>
10 10
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 const size_t kMaxBufferCount = 10; 237 const size_t kMaxBufferCount = 10;
238 iovec iov[kMaxBufferCount]; 238 iovec iov[kMaxBufferCount];
239 size_t buffer_count = std::min(buffers.size(), kMaxBufferCount); 239 size_t buffer_count = std::min(buffers.size(), kMaxBufferCount);
240 for (size_t i = 0; i < buffer_count; ++i) { 240 for (size_t i = 0; i < buffer_count; ++i) {
241 iov[i].iov_base = const_cast<char*>(buffers[i].addr); 241 iov[i].iov_base = const_cast<char*>(buffers[i].addr);
242 iov[i].iov_len = buffers[i].size; 242 iov[i].iov_len = buffers[i].size;
243 } 243 }
244 244
245 write_result = embedder::PlatformChannelSendmsgWithHandles( 245 write_result = embedder::PlatformChannelSendmsgWithHandles(
246 fd_.get(), iov, buffer_count, platform_handles, num_platform_handles); 246 fd_.get(), iov, buffer_count, platform_handles, num_platform_handles);
247 for (size_t i = 0; i < num_platform_handles; i++) 247 if (write_result >= 0) {
248 platform_handles[i].CloseIfNecessary(); 248 for (size_t i = 0; i < num_platform_handles; i++)
249 platform_handles[i].CloseIfNecessary();
250 }
249 } else { 251 } else {
250 std::vector<WriteBuffer::Buffer> buffers; 252 std::vector<WriteBuffer::Buffer> buffers;
251 write_buffer_no_lock()->GetBuffers(&buffers); 253 write_buffer_no_lock()->GetBuffers(&buffers);
252 DCHECK(!buffers.empty()); 254 DCHECK(!buffers.empty());
253 255
254 if (buffers.size() == 1) { 256 if (buffers.size() == 1) {
255 write_result = embedder::PlatformChannelWrite(fd_.get(), buffers[0].addr, 257 write_result = embedder::PlatformChannelWrite(fd_.get(), buffers[0].addr,
256 buffers[0].size); 258 buffers[0].size);
257 } else { 259 } else {
258 const size_t kMaxBufferCount = 10; 260 const size_t kMaxBufferCount = 10;
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 470
469 // Static factory method declared in raw_channel.h. 471 // Static factory method declared in raw_channel.h.
470 // static 472 // static
471 scoped_ptr<RawChannel> RawChannel::Create( 473 scoped_ptr<RawChannel> RawChannel::Create(
472 embedder::ScopedPlatformHandle handle) { 474 embedder::ScopedPlatformHandle handle) {
473 return make_scoped_ptr(new RawChannelPosix(handle.Pass())); 475 return make_scoped_ptr(new RawChannelPosix(handle.Pass()));
474 } 476 }
475 477
476 } // namespace system 478 } // namespace system
477 } // namespace mojo 479 } // namespace mojo
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698