Skip to content

Commit f337f2c

Browse files
committed
CXX-11 initialize Winsock
1 parent e77d0b1 commit f337f2c

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

src/mongo/client/scoped_db_conn_test.cpp

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,23 @@
2929
#include <boost/thread/thread.hpp>
3030

3131
// WIN32 headers included by platform/basic.h
32-
#ifndef _WIN32
32+
#if defined(_WIN32)
33+
// Initialize Winsock
34+
struct WinsockInit {
35+
WinsockInit() {
36+
37+
WSADATA wsaData;
38+
int iResult;
39+
40+
iResult = WSAStartup(MAKEWORD(2,2), &wsaData);
41+
if (iResult != 0) {
42+
printf("WSAStartup failed: %d\n", iResult);
43+
}
44+
}
45+
46+
~WinsockInit() { WSACleanup(); }
47+
} winsock_init;
48+
#else
3349
#include <arpa/inet.h>
3450
#include <sys/socket.h>
3551
#include <netdb.h>
@@ -129,8 +145,10 @@ namespace mongo {
129145

130146
void close() {
131147
if (!_closed) {
132-
::close(_fd);
148+
::shutdown(_fd, 2);
149+
::closesocket(_fd);
133150
_closed = true;
151+
_fd = -1;
134152
}
135153
}
136154

0 commit comments

Comments
 (0)