summaryrefslogtreecommitdiffstats
path: root/net/base/winsock_init.cc
blob: b7fbeaa5efbc44bd2b7c634983aa1d2a8ed05e88 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <winsock2.h>

#include "net/base/winsock_init.h"

#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);
}

void WinsockInit::Cleanup() {
  WSACleanup();
}

WinsockInit::~WinsockInit() {
  if (did_init_)
    Cleanup();
}

void EnsureWinsockInit() {
  Singleton<WinsockInit>::get();
}

}  // namespace net