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/rand_util.h" |
8 #include "base/threading/thread_restrictions.h" | 9 #include "base/threading/thread_restrictions.h" |
9 #include "base/win/scoped_handle.h" | 10 #include "base/win/scoped_handle.h" |
10 | 11 |
11 namespace base { | 12 namespace base { |
12 | 13 |
13 using win::ScopedHandle; | 14 using win::ScopedHandle; |
14 | 15 |
15 namespace { | 16 namespace { |
16 // IMPORTANT: do not change how this name is generated because it will break | 17 // IMPORTANT: do not change how this name is generated because it will break |
17 // in sandboxed scenarios as we might have by-name policies that allow pipe | 18 // in sandboxed scenarios as we might have by-name policies that allow pipe |
(...skipping 14 matching lines...) Expand all Loading... |
32 DCHECK_EQ(*socket_a, SyncSocket::kInvalidHandle); | 33 DCHECK_EQ(*socket_a, SyncSocket::kInvalidHandle); |
33 DCHECK_EQ(*socket_b, SyncSocket::kInvalidHandle); | 34 DCHECK_EQ(*socket_b, SyncSocket::kInvalidHandle); |
34 | 35 |
35 wchar_t name[kPipePathMax]; | 36 wchar_t name[kPipePathMax]; |
36 ScopedHandle handle_a; | 37 ScopedHandle handle_a; |
37 DWORD flags = PIPE_ACCESS_DUPLEX | FILE_FLAG_FIRST_PIPE_INSTANCE; | 38 DWORD flags = PIPE_ACCESS_DUPLEX | FILE_FLAG_FIRST_PIPE_INSTANCE; |
38 if (overlapped) | 39 if (overlapped) |
39 flags |= FILE_FLAG_OVERLAPPED; | 40 flags |= FILE_FLAG_OVERLAPPED; |
40 | 41 |
41 do { | 42 do { |
42 unsigned int rnd_name; | 43 unsigned long rnd_name; |
43 if (rand_s(&rnd_name) != 0) | 44 RandBytes(&rnd_name, sizeof(rnd_name)); |
44 return false; | |
45 | 45 |
46 swprintf(name, kPipePathMax, | 46 swprintf(name, kPipePathMax, |
47 kPipeNameFormat, | 47 kPipeNameFormat, |
48 GetCurrentProcessId(), | 48 GetCurrentProcessId(), |
49 GetCurrentThreadId(), | 49 GetCurrentThreadId(), |
50 rnd_name); | 50 rnd_name); |
51 | 51 |
52 handle_a.Set(CreateNamedPipeW( | 52 handle_a.Set(CreateNamedPipeW( |
53 name, | 53 name, |
54 flags, | 54 flags, |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 static_cast<DWORD>(timeout.InMilliseconds())); | 333 static_cast<DWORD>(timeout.InMilliseconds())); |
334 } | 334 } |
335 | 335 |
336 // static | 336 // static |
337 bool CancelableSyncSocket::CreatePair(CancelableSyncSocket* socket_a, | 337 bool CancelableSyncSocket::CreatePair(CancelableSyncSocket* socket_a, |
338 CancelableSyncSocket* socket_b) { | 338 CancelableSyncSocket* socket_b) { |
339 return CreatePairImpl(&socket_a->handle_, &socket_b->handle_, true); | 339 return CreatePairImpl(&socket_a->handle_, &socket_b->handle_, true); |
340 } | 340 } |
341 | 341 |
342 } // namespace base | 342 } // namespace base |
OLD | NEW |