aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/poco/Net/src/Net.cpp
blob: e81b4b54590c329d96e1fdc2de71daf4c1a8f2d9 (plain) (blame)
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
//
// Net.cpp
//
// Library: Net
// Package: NetCore
// Module:  NetCore
//
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier:	BSL-1.0
//


#include "Poco/Net/Net.h"


#include "Poco/Net/SocketDefs.h"
#include "Poco/Net/NetException.h"


namespace Poco {
namespace Net {


void Net_API initializeNetwork()
{
#if defined(POCO_OS_FAMILY_WINDOWS)
	WORD    version = MAKEWORD(2, 2);
	WSADATA data;
	if (WSAStartup(version, &data) != 0)
		throw NetException("Failed to initialize network subsystem");
#endif
}


void Net_API uninitializeNetwork()
{
#if defined(POCO_OS_FAMILY_WINDOWS)
	WSACleanup();
#endif
}


} } // namespace Poco::Net


#if defined(POCO_OS_FAMILY_WINDOWS) && !defined(POCO_NO_AUTOMATIC_LIB_INIT)

	struct NetworkInitializer
		/// Network initializer for windows statically
		/// linked library.
	{
		NetworkInitializer()
			/// Calls Poco::Net::initializeNetwork();
		{
			Poco::Net::initializeNetwork();
		}

		~NetworkInitializer()
			/// Calls Poco::Net::uninitializeNetwork();
		{
			try
			{
				Poco::Net::uninitializeNetwork();
			}
			catch (...)
			{
				poco_unexpected();
			}
		}
	};

	const NetworkInitializer pocoNetworkInitializer;

#endif