Skip to content

Commit

Permalink
Attempt at windows socket fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonas Nilsson committed Feb 23, 2017
1 parent d2df380 commit 8c014c4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions include/graylog_logger/GraylogConnection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,7 @@ class GraylogConnection {
mutable std::mutex stateMutex;
ConStatus retConState;
ConcurrentQueue<ConStatus> stateQueue;
#ifdef _WIN32
WSADATA wsaData;
#endif
};
7 changes: 7 additions & 0 deletions src/GraylogConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,16 @@

GraylogConnection::GraylogConnection(std::string host, int port) : closeThread(false), host(host), port(std::to_string(port)), socketFd(-1), conAddresses(NULL), connectionTries(0), firstMessage(true) {
retConState = GraylogConnection::ConStatus::NONE;
#ifdef _WIN32
WSAStartup(MAKEWORD(2, 2), &wsaData);
#endif
connectionThread = std::thread(&GraylogConnection::ThreadFunction, this);
}

GraylogConnection::~GraylogConnection() {
#ifdef _WIN32
WSACleanup();
#endif
EndThread();
}

Expand Down Expand Up @@ -67,6 +73,7 @@ void GraylogConnection::MakeConnectionHints() {
//hints.ai_family = AF_UNSPEC; //Accept both IPv4 and IPv6
hints.ai_family = AF_INET; //Accept only IPv4
hints.ai_socktype = SOCK_STREAM; //Use TCP
hints.ai_protocol = IPPROTO_TCP;
}

void GraylogConnection::GetServerAddr() {
Expand Down

0 comments on commit 8c014c4

Please sign in to comment.