OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/sync_socket.h" | 5 #include "base/sync_socket.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/threading/thread_restrictions.h" | 8 #include "base/threading/thread_restrictions.h" |
9 #include "base/win/scoped_handle.h" | 9 #include "base/win/scoped_handle.h" |
10 | 10 |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
200 | 200 |
201 SyncSocket::~SyncSocket() { | 201 SyncSocket::~SyncSocket() { |
202 Close(); | 202 Close(); |
203 } | 203 } |
204 | 204 |
205 // static | 205 // static |
206 bool SyncSocket::CreatePair(SyncSocket* socket_a, SyncSocket* socket_b) { | 206 bool SyncSocket::CreatePair(SyncSocket* socket_a, SyncSocket* socket_b) { |
207 return CreatePairImpl(&socket_a->handle_, &socket_b->handle_, false); | 207 return CreatePairImpl(&socket_a->handle_, &socket_b->handle_, false); |
208 } | 208 } |
209 | 209 |
210 // static | |
211 SyncSocket::Handle SyncSocket::UnwrapHandle( | |
212 const SyncSocket::TransitDescriptor& descriptor) { | |
213 return static_cast<SyncSocket::Handle>(descriptor); | |
214 } | |
215 | |
216 bool SyncSocket::PrepareTransitDescriptor( | |
217 ProcessHandle peer_process_handle, | |
218 SyncSocket::TransitDescriptor* descriptor) { | |
219 DCHECK(descriptor); | |
220 *descriptor = 0; | |
221 if (!::DuplicateHandle(GetCurrentProcess(), handle(), peer_process_handle, | |
222 descriptor, 0, FALSE, DUPLICATE_SAME_ACCESS)) { | |
223 DPLOG(ERROR) << "Cannot duplicate socket handle for peer process."; | |
224 return false; | |
225 } | |
226 if (*descriptor == 0) { | |
tommi (sloooow) - chröme
2014/09/04 17:02:25
I would remove this block. If DuplicateHandle has
burnik
2014/09/04 18:04:07
Done.
| |
227 NOTREACHED() << "Socket handle duplicated but equals to zero."; | |
228 return false; | |
229 } | |
230 return true; | |
231 } | |
232 | |
210 bool SyncSocket::Close() { | 233 bool SyncSocket::Close() { |
211 if (handle_ == kInvalidHandle) | 234 if (handle_ == kInvalidHandle) |
212 return true; | 235 return true; |
213 | 236 |
214 const BOOL result = CloseHandle(handle_); | 237 const BOOL result = CloseHandle(handle_); |
215 handle_ = kInvalidHandle; | 238 handle_ = kInvalidHandle; |
216 return result == TRUE; | 239 return result == TRUE; |
217 } | 240 } |
218 | 241 |
219 size_t SyncSocket::Send(const void* buffer, size_t length) { | 242 size_t SyncSocket::Send(const void* buffer, size_t length) { |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
308 &file_operation_, &shutdown_event_, this, timeout.InMilliseconds()); | 331 &file_operation_, &shutdown_event_, this, timeout.InMilliseconds()); |
309 } | 332 } |
310 | 333 |
311 // static | 334 // static |
312 bool CancelableSyncSocket::CreatePair(CancelableSyncSocket* socket_a, | 335 bool CancelableSyncSocket::CreatePair(CancelableSyncSocket* socket_a, |
313 CancelableSyncSocket* socket_b) { | 336 CancelableSyncSocket* socket_b) { |
314 return CreatePairImpl(&socket_a->handle_, &socket_b->handle_, true); | 337 return CreatePairImpl(&socket_a->handle_, &socket_b->handle_, true); |
315 } | 338 } |
316 | 339 |
317 } // namespace base | 340 } // namespace base |
OLD | NEW |