Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <winsock2.h> | 5 #include <winsock2.h> |
| 6 | 6 |
| 7 #include "net/base/winsock_init.h" | 7 #include "net/base/winsock_init.h" |
| 8 | 8 |
| 9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 23 // The first time WSAGetLastError is called, the delay load helper will | 23 // The first time WSAGetLastError is called, the delay load helper will |
| 24 // resolve the address with GetProcAddress and fixup the import. If a | 24 // resolve the address with GetProcAddress and fixup the import. If a |
| 25 // third party application hooks system functions without correctly | 25 // third party application hooks system functions without correctly |
| 26 // restoring the error code, it is possible that the error code will be | 26 // restoring the error code, it is possible that the error code will be |
| 27 // overwritten during delay load resolution. The result of the first | 27 // overwritten during delay load resolution. The result of the first |
| 28 // call may be incorrect, so make sure the function is bound and future | 28 // call may be incorrect, so make sure the function is bound and future |
| 29 // results will be correct. | 29 // results will be correct. |
| 30 WSAGetLastError(); | 30 WSAGetLastError(); |
| 31 } | 31 } |
| 32 } | 32 } |
| 33 | |
| 34 ~WinsockInitSingleton() { | |
|
gab
2016/07/27 14:29:17
On the bug when I said "delete the destructor" I m
gab
2016/08/09 16:46:32
ping, I think this would be cleaner, can you do th
| |
| 35 // Don't call WSACleanup() since the worker pool threads can continue to | |
| 36 // call getaddrinfo() after Winsock has shutdown, which can lead to crashes. | |
| 37 } | |
| 38 }; | 33 }; |
| 39 | 34 |
| 40 static base::LazyInstance<WinsockInitSingleton> g_winsock_init_singleton = | 35 // Worker pool threads that use the Windows Sockets API may still be running at |
| 41 LAZY_INSTANCE_INITIALIZER; | 36 // shutdown. Leak instance and skip cleanup. |
| 37 static base::LazyInstance<WinsockInitSingleton>::Leaky | |
| 38 g_winsock_init_singleton = LAZY_INSTANCE_INITIALIZER; | |
| 42 | 39 |
| 43 } // namespace | 40 } // namespace |
| 44 | 41 |
| 45 namespace net { | 42 namespace net { |
| 46 | 43 |
| 47 void EnsureWinsockInit() { | 44 void EnsureWinsockInit() { |
| 48 g_winsock_init_singleton.Get(); | 45 g_winsock_init_singleton.Get(); |
| 49 } | 46 } |
| 50 | 47 |
| 51 } // namespace net | 48 } // namespace net |
| OLD | NEW |