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

Side by Side Diff: mojo/embedder/platform_channel_utils_posix.cc

Issue 292983007: Mojo: Make PlatformChannelRecvmsg() append handles to a deque instead. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review comments Created 6 years, 7 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
« no previous file with comments | « mojo/embedder/platform_channel_utils_posix.h ('k') | mojo/embedder/platform_handle_utils.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/embedder/platform_channel_utils_posix.h" 5 #include "mojo/embedder/platform_channel_utils_posix.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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 } 98 }
99 99
100 for (size_t i = 0; i < num_handles; i++) 100 for (size_t i = 0; i < num_handles; i++)
101 handles[i].CloseIfNecessary(); 101 handles[i].CloseIfNecessary();
102 return true; 102 return true;
103 } 103 }
104 104
105 ssize_t PlatformChannelRecvmsg(PlatformHandle h, 105 ssize_t PlatformChannelRecvmsg(PlatformHandle h,
106 void* buf, 106 void* buf,
107 size_t num_bytes, 107 size_t num_bytes,
108 ScopedPlatformHandleVectorPtr* handles) { 108 std::deque<PlatformHandle>* platform_handles) {
109 DCHECK(buf); 109 DCHECK(buf);
110 DCHECK_GT(num_bytes, 0u); 110 DCHECK_GT(num_bytes, 0u);
111 DCHECK(handles); 111 DCHECK(platform_handles);
112 112
113 struct iovec iov = { buf, num_bytes }; 113 struct iovec iov = { buf, num_bytes };
114 char cmsg_buf[CMSG_SPACE(kPlatformChannelMaxNumHandles * sizeof(int))]; 114 char cmsg_buf[CMSG_SPACE(kPlatformChannelMaxNumHandles * sizeof(int))];
115 struct msghdr msg = {}; 115 struct msghdr msg = {};
116 msg.msg_iov = &iov; 116 msg.msg_iov = &iov;
117 msg.msg_iovlen = 1; 117 msg.msg_iovlen = 1;
118 msg.msg_control = cmsg_buf; 118 msg.msg_control = cmsg_buf;
119 msg.msg_controllen = sizeof(cmsg_buf); 119 msg.msg_controllen = sizeof(cmsg_buf);
120 120
121 ssize_t result = HANDLE_EINTR(recvmsg(h.fd, &msg, MSG_DONTWAIT)); 121 ssize_t result = HANDLE_EINTR(recvmsg(h.fd, &msg, MSG_DONTWAIT));
122 if (result < 0) 122 if (result < 0)
123 return result; 123 return result;
124 124
125 // Success; no control messages. 125 // Success; no control messages.
126 if (msg.msg_controllen == 0) 126 if (msg.msg_controllen == 0)
127 return result; 127 return result;
128 128
129 DCHECK(!(msg.msg_flags & MSG_CTRUNC)); 129 DCHECK(!(msg.msg_flags & MSG_CTRUNC));
130 130
131 for (cmsghdr* cmsg = CMSG_FIRSTHDR(&msg); 131 for (cmsghdr* cmsg = CMSG_FIRSTHDR(&msg);
132 cmsg; 132 cmsg;
133 cmsg = CMSG_NXTHDR(&msg, cmsg)) { 133 cmsg = CMSG_NXTHDR(&msg, cmsg)) {
134 if (cmsg->cmsg_level == SOL_SOCKET && cmsg->cmsg_type == SCM_RIGHTS) { 134 if (cmsg->cmsg_level == SOL_SOCKET && cmsg->cmsg_type == SCM_RIGHTS) {
135 size_t payload_length = cmsg->cmsg_len - CMSG_LEN(0); 135 size_t payload_length = cmsg->cmsg_len - CMSG_LEN(0);
136 DCHECK_EQ(payload_length % sizeof(int), 0u); 136 DCHECK_EQ(payload_length % sizeof(int), 0u);
137 size_t num_fds = payload_length / sizeof(int); 137 size_t num_fds = payload_length / sizeof(int);
138 const int* fds = reinterpret_cast<int*>(CMSG_DATA(cmsg)); 138 const int* fds = reinterpret_cast<int*>(CMSG_DATA(cmsg));
139 for (size_t i = 0; i < num_fds; i++) { 139 for (size_t i = 0; i < num_fds; i++) {
140 if (!*handles) 140 platform_handles->push_back(PlatformHandle(fds[i]));
141 (*handles).reset(new PlatformHandleVector()); 141 DCHECK(platform_handles->back().is_valid());
142 (*handles)->push_back(PlatformHandle(fds[i]));
143 DCHECK((*handles)->back().is_valid());
144 } 142 }
145 } 143 }
146 } 144 }
147 145
148 return result; 146 return result;
149 } 147 }
150 148
151 } // namespace embedder 149 } // namespace embedder
152 } // namespace mojo 150 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/embedder/platform_channel_utils_posix.h ('k') | mojo/embedder/platform_handle_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698