]> git.proxmox.com Git - ceph.git/blob - ceph/src/jaegertracing/jaeger-client-cpp/src/jaegertracing/net/Socket.cpp
buildsys: switch source download to quincy
[ceph.git] / ceph / src / jaegertracing / jaeger-client-cpp / src / jaegertracing / net / Socket.cpp
1 /*
2 * Copyright (c) 2017 Uber Technologies, Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include "jaegertracing/net/Socket.h"
18
19 #ifdef WIN32
20
21 #include <stdio.h>
22 #include <windows.h>
23 #include <winsock2.h>
24 #include <ws2tcpip.h>
25
26 #endif
27
28 namespace jaegertracing {
29 namespace net {
30
31 namespace {
32
33
34 void initSocket()
35 {
36 #ifdef WIN32
37 /* Use the MAKEWORD(lowbyte, highbyte) macro declared in Windef.h */
38 WORD wVersionRequested = MAKEWORD(2, 2);
39
40 WSADATA wsaData;
41 int err = WSAStartup(wVersionRequested, &wsaData);
42 if (err != 0) {
43 std::ostringstream oss;
44 oss << "Failed to find a usable Winsock DLL. WSAStartup failed with "
45 "error "
46 << err;
47 throw std::system_error(errno, std::system_category(), oss.str());
48 }
49
50 /* Confirm that the WinSock DLL supports 2.2.*/
51 /* Note that if the DLL supports versions greater */
52 /* than 2.2 in addition to 2.2, it will still return */
53 /* 2.2 in wVersion since that is the version we */
54 /* requested. */
55
56 if (LOBYTE(wsaData.wVersion) != 2 || HIBYTE(wsaData.wVersion) != 2) {
57 WSACleanup();
58
59 std::ostringstream oss;
60 oss << "Failed to find a usable Winsock DLL. WSAStartup failed with "
61 "error "
62 << err;
63 throw std::system_error(errno, std::system_category(), oss.str());
64 }
65 #endif
66 }
67
68 void cleanSocket()
69 {
70 #ifdef WIN32
71 WSACleanup();
72 #endif
73 }
74
75 }
76
77
78 Socket::OSResource::OSResource() { initSocket(); }
79
80 Socket::OSResource::~OSResource() { cleanSocket(); }
81
82
83 } // namespace net
84 } // namespace jaegertracing