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

Side by Side Diff: mojo/edk/embedder/platform_channel_utils.cc

Issue 1478503003: EDK: Convert most uses of PlatformHandleVector to std::vector<ScopedPlatformHandle>. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years 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 | « mojo/edk/embedder/platform_channel_utils.h ('k') | mojo/edk/system/channel.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/embedder/platform_channel_utils.h" 5 #include "mojo/edk/embedder/platform_channel_utils.h"
6 6
7 #include <sys/socket.h> 7 #include <sys/socket.h>
8 #include <sys/uio.h> 8 #include <sys/uio.h>
9 #include <unistd.h> 9 #include <unistd.h>
10 10
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 if (result < 1) { 132 if (result < 1) {
133 DCHECK_EQ(result, -1); 133 DCHECK_EQ(result, -1);
134 return false; 134 return false;
135 } 135 }
136 136
137 for (size_t i = 0; i < num_handles; i++) 137 for (size_t i = 0; i < num_handles; i++)
138 handles[i].CloseIfNecessary(); 138 handles[i].CloseIfNecessary();
139 return true; 139 return true;
140 } 140 }
141 141
142 ssize_t PlatformChannelRecvmsg(PlatformHandle h, 142 ssize_t PlatformChannelRecvmsg(
143 void* buf, 143 PlatformHandle h,
144 size_t num_bytes, 144 void* buf,
145 std::deque<PlatformHandle>* platform_handles) { 145 size_t num_bytes,
146 std::deque<ScopedPlatformHandle>* platform_handles) {
146 DCHECK(buf); 147 DCHECK(buf);
147 DCHECK_GT(num_bytes, 0u); 148 DCHECK_GT(num_bytes, 0u);
148 DCHECK(platform_handles); 149 DCHECK(platform_handles);
149 150
150 struct iovec iov = {buf, num_bytes}; 151 struct iovec iov = {buf, num_bytes};
151 char cmsg_buf[CMSG_SPACE(kPlatformChannelMaxNumHandles * sizeof(int))]; 152 char cmsg_buf[CMSG_SPACE(kPlatformChannelMaxNumHandles * sizeof(int))];
152 struct msghdr msg = {}; 153 struct msghdr msg = {};
153 msg.msg_iov = &iov; 154 msg.msg_iov = &iov;
154 msg.msg_iovlen = 1; 155 msg.msg_iovlen = 1;
155 msg.msg_control = cmsg_buf; 156 msg.msg_control = cmsg_buf;
(...skipping 10 matching lines...) Expand all
166 DCHECK(!(msg.msg_flags & MSG_CTRUNC)); 167 DCHECK(!(msg.msg_flags & MSG_CTRUNC));
167 168
168 for (cmsghdr* cmsg = CMSG_FIRSTHDR(&msg); cmsg; 169 for (cmsghdr* cmsg = CMSG_FIRSTHDR(&msg); cmsg;
169 cmsg = CMSG_NXTHDR(&msg, cmsg)) { 170 cmsg = CMSG_NXTHDR(&msg, cmsg)) {
170 if (cmsg->cmsg_level == SOL_SOCKET && cmsg->cmsg_type == SCM_RIGHTS) { 171 if (cmsg->cmsg_level == SOL_SOCKET && cmsg->cmsg_type == SCM_RIGHTS) {
171 size_t payload_length = cmsg->cmsg_len - CMSG_LEN(0); 172 size_t payload_length = cmsg->cmsg_len - CMSG_LEN(0);
172 DCHECK_EQ(payload_length % sizeof(int), 0u); 173 DCHECK_EQ(payload_length % sizeof(int), 0u);
173 size_t num_fds = payload_length / sizeof(int); 174 size_t num_fds = payload_length / sizeof(int);
174 const int* fds = reinterpret_cast<int*>(CMSG_DATA(cmsg)); 175 const int* fds = reinterpret_cast<int*>(CMSG_DATA(cmsg));
175 for (size_t i = 0; i < num_fds; i++) { 176 for (size_t i = 0; i < num_fds; i++) {
176 platform_handles->push_back(PlatformHandle(fds[i])); 177 platform_handles->push_back(
178 ScopedPlatformHandle(PlatformHandle(fds[i])));
177 DCHECK(platform_handles->back().is_valid()); 179 DCHECK(platform_handles->back().is_valid());
178 } 180 }
179 } 181 }
180 } 182 }
181 183
182 return result; 184 return result;
183 } 185 }
184 186
185 } // namespace embedder 187 } // namespace embedder
186 } // namespace mojo 188 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/embedder/platform_channel_utils.h ('k') | mojo/edk/system/channel.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698