blob: 134c7b0dbb2df7c8df6d52226c34462f5a571c94 [file] [log] [blame]
Roger Meier84e4a3c2011-09-16 20:58:44 +00001/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20#ifndef _THRIFT_TRANSPORT_WINDOWS_TWINSOCKSINGLETON_H_
21#define _THRIFT_TRANSPORT_WINDOWS_TWINSOCKSINGLETON_H_ 1
22
23#if defined(_MSC_VER) && (_MSC_VER > 1200)
24#pragma once
25#endif // _MSC_VER
26
27#ifndef _WIN32
28#error This is a MSVC header only.
29#endif
30
31// boost
32#include <boost/noncopyable.hpp>
33#include <boost/scoped_ptr.hpp>
34#include <boost/thread/once.hpp>
35
36namespace apache { namespace thrift { namespace transport {
37
38/**
39 * Winsock2 must be intialised once only in order to create sockets. This class
40 * performs a one time initialisation when create is called.
41 */
42class TWinsockSingleton : private boost::noncopyable
43{
44
45public:
46
47 typedef boost::scoped_ptr<TWinsockSingleton> instance_ptr;
48
49private:
50
51 friend void boost::call_once(void (*func)(void), boost::once_flag& flag);
52
53private:
54
55 TWinsockSingleton(void);
56
57public:
58
59 ~TWinsockSingleton(void);
60
61public:
62
63 static void create(void);
64
65private:
66
67 static void init(void);
68
69private:
70
71 static instance_ptr instance_ptr_;
72 static boost::once_flag flags_;
73};
74
75}}} // apache::thrift::transport
76
77#endif // _THRIFT_TRANSPORT_WINDOWS_TWINSOCKSINGLETON_H_