147be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org/*
247be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org *  Copyright 2009 The WebRTC Project Authors. All rights reserved.
347be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org *
447be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org *  Use of this source code is governed by a BSD-style license
547be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org *  that can be found in the LICENSE file in the root of the source
647be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org *  tree. An additional intellectual property rights grant can be found
747be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org *  in the file PATENTS.  All contributing project authors may
847be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org *  be found in the AUTHORS file in the root of the source tree.
947be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org */
1047be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org
1147be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org#include "webrtc/base/win32socketinit.h"
1247be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org
1347be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org#include "webrtc/base/win32.h"
1447be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org
1547be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.orgnamespace rtc {
1647be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org
1747be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org// Please don't remove this function.
1847be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.orgvoid EnsureWinsockInit() {
1947be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org  // The default implementation uses a global initializer, so WSAStartup
2047be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org  // happens at module load time.  Thus we don't need to do anything here.
2147be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org  // The hook is provided so that a client that statically links with
2247be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org  // libjingle can override it, to provide its own initialization.
2347be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org}
2447be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org
2547be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org#if defined(WEBRTC_WIN)
2647be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.orgclass WinsockInitializer {
2747be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org public:
2847be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org  WinsockInitializer() {
2947be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org    WSADATA wsaData;
3047be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org    WORD wVersionRequested = MAKEWORD(1, 0);
3147be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org    err_ = WSAStartup(wVersionRequested, &wsaData);
3247be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org  }
3347be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org  ~WinsockInitializer() {
3447be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org    if (!err_)
3547be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org      WSACleanup();
3647be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org  }
3747be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org  int error() {
3847be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org    return err_;
3947be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org  }
4047be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org private:
4147be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org  int err_;
4247be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org};
4347be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.orgWinsockInitializer g_winsockinit;
4447be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org#endif
4547be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org
4647be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org}  // namespace rtc
47