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); | |
tommi (sloooow) - chröme
2014/09/04 11:34:10
nit: "SyncSocket::" necessary?
burnik
2014/09/04 12:24:44
Guess not. Although rest of the code looks kind of
tommi (sloooow) - chröme
2014/09/04 17:02:25
The rest of the code only uses it outside the scop
burnik
2014/09/04 18:04:07
Done.
| |
214 } | |
215 | |
216 bool SyncSocket::PrepareTransitDescriptor( | |
217 ProcessHandle peer_process_handle, | |
218 SyncSocket::TransitDescriptor* descriptor) { | |
219 // |TransitDescriptor| on Windows is the |Handle| itself. | |
220 ::DuplicateHandle(GetCurrentProcess(), handle(), peer_process_handle, | |
tommi (sloooow) - chröme
2014/09/04 11:34:10
I'd like to check the return value of this call an
burnik
2014/09/04 12:24:44
Done.
| |
221 descriptor, 0, FALSE, DUPLICATE_SAME_ACCESS); | |
222 return (*descriptor != 0); | |
tommi (sloooow) - chröme
2014/09/04 11:34:10
If the caller does this:
SyncSocket::TransitDescr
burnik
2014/09/04 12:24:44
Yes, good point since this is on the stack.
On 201
| |
223 } | |
224 | |
210 bool SyncSocket::Close() { | 225 bool SyncSocket::Close() { |
211 if (handle_ == kInvalidHandle) | 226 if (handle_ == kInvalidHandle) |
212 return true; | 227 return true; |
213 | 228 |
214 const BOOL result = CloseHandle(handle_); | 229 const BOOL result = CloseHandle(handle_); |
215 handle_ = kInvalidHandle; | 230 handle_ = kInvalidHandle; |
216 return result == TRUE; | 231 return result == TRUE; |
217 } | 232 } |
218 | 233 |
219 size_t SyncSocket::Send(const void* buffer, size_t length) { | 234 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()); | 323 &file_operation_, &shutdown_event_, this, timeout.InMilliseconds()); |
309 } | 324 } |
310 | 325 |
311 // static | 326 // static |
312 bool CancelableSyncSocket::CreatePair(CancelableSyncSocket* socket_a, | 327 bool CancelableSyncSocket::CreatePair(CancelableSyncSocket* socket_a, |
313 CancelableSyncSocket* socket_b) { | 328 CancelableSyncSocket* socket_b) { |
314 return CreatePairImpl(&socket_a->handle_, &socket_b->handle_, true); | 329 return CreatePairImpl(&socket_a->handle_, &socket_b->handle_, true); |
315 } | 330 } |
316 | 331 |
317 } // namespace base | 332 } // namespace base |
OLD | NEW |