diff --git a/include/rtc/include.hpp b/include/rtc/include.hpp index 5bba735..3fd07c4 100644 --- a/include/rtc/include.hpp +++ b/include/rtc/include.hpp @@ -20,6 +20,7 @@ #define RTC_INCLUDE_H #ifdef _WIN32 +#define WIN32_LEAN_AND_MEAN #ifndef _WIN32_WINNT #define _WIN32_WINNT 0x0602 #endif diff --git a/src/datachannel.cpp b/src/datachannel.cpp index cbfb78c..5271d11 100644 --- a/src/datachannel.cpp +++ b/src/datachannel.cpp @@ -21,6 +21,12 @@ #include "peerconnection.hpp" #include "sctptransport.hpp" +#ifdef _WIN32 +#include +#else +#include +#endif + namespace rtc { using std::shared_ptr; diff --git a/src/icetransport.cpp b/src/icetransport.cpp index f2123d5..025f3d7 100644 --- a/src/icetransport.cpp +++ b/src/icetransport.cpp @@ -19,9 +19,15 @@ #include "icetransport.hpp" #include "configuration.hpp" +#include +#include +#include + #ifdef _WIN32 #include -#elif __linux__ +#include +#else +#include #include #include #include @@ -29,10 +35,6 @@ #include -#include -#include -#include - using namespace std::chrono_literals; using std::shared_ptr; diff --git a/src/peerconnection.cpp b/src/peerconnection.cpp index c35c156..85f0af7 100644 --- a/src/peerconnection.cpp +++ b/src/peerconnection.cpp @@ -25,6 +25,10 @@ #include +#ifdef _WIN32 +#include +#endif + namespace rtc { using namespace std::placeholders; @@ -32,7 +36,13 @@ using namespace std::placeholders; using std::shared_ptr; using std::weak_ptr; -PeerConnection::PeerConnection() : PeerConnection(Configuration()) {} +PeerConnection::PeerConnection() : PeerConnection(Configuration()) { +#ifdef _WIN32 + WSADATA wsaData; + if (WSAStartup(MAKEWORD(2, 2), &wsaData)) + throw std::runtime_error("WSAStartup failed, error=" + std::to_string(WSAGetLastError())); +#endif +} PeerConnection::PeerConnection(const Configuration &config) : mConfig(config), mCertificate(make_certificate("libdatachannel")), mState(State::New) {} @@ -43,6 +53,10 @@ PeerConnection::~PeerConnection() { mSctpTransport.reset(); mDtlsTransport.reset(); mIceTransport.reset(); + +#ifdef _WIN32 + WSACleanup(); +#endif } void PeerConnection::close() { diff --git a/src/sctptransport.cpp b/src/sctptransport.cpp index 9d32986..281efcf 100644 --- a/src/sctptransport.cpp +++ b/src/sctptransport.cpp @@ -23,10 +23,6 @@ #include #include -#ifdef __linux__ -#include -#endif - #ifdef USE_JUICE #ifndef __APPLE__ // libjuice enables Linux path MTU discovery or sets the DF flag diff --git a/src/sctptransport.hpp b/src/sctptransport.hpp index 2548443..a37e199 100644 --- a/src/sctptransport.hpp +++ b/src/sctptransport.hpp @@ -29,14 +29,6 @@ #include #include -#ifdef _WIN32 -#include -#elif __linux__ -#include -#endif - -#include - #include "usrsctp.h" namespace rtc { diff --git a/test/main.cpp b/test/main.cpp index 6b1605b..edd8d1b 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -23,10 +23,6 @@ #include #include -#ifdef _WIN32 -#include -#endif - using namespace rtc; using namespace std; @@ -35,12 +31,6 @@ template weak_ptr make_weak_ptr(shared_ptr ptr) { return ptr; } int main(int argc, char **argv) { InitLogger(LogLevel::Debug); -#ifdef _WIN32 - WSADATA wsaData; - if (WSAStartup(MAKEWORD(2, 2), &wsaData)) - throw std::runtime_error("WSAStartup failed, error=" + std::to_string(WSAGetLastError())); -#endif - Configuration config; // config.iceServers.emplace_back("stun:stun.l.google.com:19302"); // config.iceServers.emplace_back(IceServer("TURN_SERVER_URL", "PORT", "USERNAME", "PASSWORD", @@ -137,10 +127,5 @@ int main(int argc, char **argv) { } else { cout << "Failure" << endl; } - -#ifdef _WIN32 - WSACleanup(); -#endif - - return success ? 0 : 1; + return success ? 0 : 1; } diff --git a/test/p2p/answerer.cpp b/test/p2p/answerer.cpp index b1c5e13..f9efb45 100644 --- a/test/p2p/answerer.cpp +++ b/test/p2p/answerer.cpp @@ -23,10 +23,6 @@ #include #include -#ifdef _WIN32 -#include -#endif - using namespace rtc; using namespace std; @@ -35,12 +31,6 @@ template weak_ptr make_weak_ptr(shared_ptr ptr) { return ptr; } int main(int argc, char **argv) { InitLogger(LogLevel::Warning); -#ifdef _WIN32 - WSADATA wsaData; - if (WSAStartup(MAKEWORD(2, 2), &wsaData)) - throw std::runtime_error("WSAStartup failed, error=" + std::to_string(WSAGetLastError())); -#endif - Configuration config; // config.iceServers.emplace_back("stun.l.google.com:19302"); @@ -141,8 +131,4 @@ int main(int argc, char **argv) { dc->close(); if (pc) pc->close(); - -#ifdef _WIN32 - WSACleanup(); -#endif } diff --git a/test/p2p/offerer.cpp b/test/p2p/offerer.cpp index 43c635e..ff2b101 100644 --- a/test/p2p/offerer.cpp +++ b/test/p2p/offerer.cpp @@ -23,10 +23,6 @@ #include #include -#ifdef _WIN32 -#include -#endif - using namespace rtc; using namespace std; @@ -35,12 +31,6 @@ template weak_ptr make_weak_ptr(shared_ptr ptr) { return ptr; } int main(int argc, char **argv) { InitLogger(LogLevel::Warning); -#ifdef _WIN32 - WSADATA wsaData; - if (WSAStartup(MAKEWORD(2, 2), &wsaData)) - throw std::runtime_error("WSAStartup failed, error=" + std::to_string(WSAGetLastError())); -#endif - Configuration config; // config.iceServers.emplace_back("stun.l.google.com:19302"); @@ -141,8 +131,4 @@ int main(int argc, char **argv) { dc->close(); if (pc) pc->close(); - -#ifdef _WIN32 - WSACleanup(); -#endif }