summaryrefslogtreecommitdiffstats
path: root/net/base/winsock_init.cc
diff options
context:
space:
mode:
authordeanm@chromium.org <deanm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-10-06 10:41:35 +0000
committerdeanm@chromium.org <deanm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-10-06 10:41:35 +0000
commit14d5cfbd4ceb886e92033092603f369e184539e0 (patch)
treea3d275f05a9e361581b964f33f9cbfb15a0fb2db /net/base/winsock_init.cc
parent02c8796f86e238be73fecd15b894724d58a96f4d (diff)
downloadchromium_src-14d5cfbd4ceb886e92033092603f369e184539e0.zip
chromium_src-14d5cfbd4ceb886e92033092603f369e184539e0.tar.gz
chromium_src-14d5cfbd4ceb886e92033092603f369e184539e0.tar.bz2
- Cleanup usage, EnsureWinsockInit is now the only method of initializing.
- Work around buggy third party hooks that can overwrite LastErrorValue during delay load binding. Review URL: http://codereview.chromium.org/6483 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@2877 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/base/winsock_init.cc')
-rw-r--r--net/base/winsock_init.cc51
1 files changed, 30 insertions, 21 deletions
diff --git a/net/base/winsock_init.cc b/net/base/winsock_init.cc
index b7fbeaa..190ed77 100644
--- a/net/base/winsock_init.cc
+++ b/net/base/winsock_init.cc
@@ -8,30 +8,39 @@
#include "base/singleton.h"
-namespace net {
-
-WinsockInit::WinsockInit() : did_init_(false) {
- did_init_ = Init();
-}
-
-bool WinsockInit::Init() {
- WORD winsock_ver = MAKEWORD(2,2);
- WSAData wsa_data;
- return (WSAStartup(winsock_ver, &wsa_data) == 0);
-}
+namespace {
+
+class WinsockInitSingleton {
+ public:
+ WinsockInitSingleton() : did_init_(false) {
+ WORD winsock_ver = MAKEWORD(2,2);
+ WSAData wsa_data;
+ did_init_ = (WSAStartup(winsock_ver, &wsa_data) == 0);
+
+ // The first time WSAGetLastError is called, the delay load helper will
+ // resolve the address with GetProcAddress and fixup the import. If a third
+ // party application hooks system functions without correctly restoring the
+ // error code, it is possible that the error code will be overwritten during
+ // delay load resolution. The result of the first call may be incorrect, so
+ // make sure the function is bound and future results will be correct.
+ WSAGetLastError();
+ }
+
+ ~WinsockInitSingleton() {
+ if (did_init_)
+ WSACleanup();
+ }
+
+ private:
+ bool did_init_;
+};
+
+} // namespace
-void WinsockInit::Cleanup() {
- WSACleanup();
-}
-
-WinsockInit::~WinsockInit() {
- if (did_init_)
- Cleanup();
-}
+namespace net {
void EnsureWinsockInit() {
- Singleton<WinsockInit>::get();
+ Singleton<WinsockInitSingleton>::get();
}
} // namespace net
-