Added WSAStartup call in PeerConnection and cleaned up includes

This commit is contained in:
Paul-Louis Ageneau
2020-03-05 20:37:58 +01:00
parent 3367eba4fe
commit 9441f78494
9 changed files with 30 additions and 62 deletions

View File

@ -20,6 +20,7 @@
#define RTC_INCLUDE_H
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0602
#endif

View File

@ -21,6 +21,12 @@
#include "peerconnection.hpp"
#include "sctptransport.hpp"
#ifdef _WIN32
#include <winsock2.h>
#else
#include <arpa/inet.h>
#endif
namespace rtc {
using std::shared_ptr;

View File

@ -19,9 +19,15 @@
#include "icetransport.hpp"
#include "configuration.hpp"
#include <iostream>
#include <random>
#include <sstream>
#ifdef _WIN32
#include <winsock2.h>
#elif __linux__
#include <ws2tcpip.h>
#else
#include <arpa/inet.h>
#include <netdb.h>
#include <netinet/in.h>
#include <sys/socket.h>
@ -29,10 +35,6 @@
#include <sys/types.h>
#include <iostream>
#include <random>
#include <sstream>
using namespace std::chrono_literals;
using std::shared_ptr;

View File

@ -25,6 +25,10 @@
#include <iostream>
#ifdef _WIN32
#include <winsock2.h>
#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() {

View File

@ -23,10 +23,6 @@
#include <iostream>
#include <vector>
#ifdef __linux__
#include <arpa/inet.h>
#endif
#ifdef USE_JUICE
#ifndef __APPLE__
// libjuice enables Linux path MTU discovery or sets the DF flag

View File

@ -29,14 +29,6 @@
#include <map>
#include <mutex>
#ifdef _WIN32
#include <winsock2.h>
#elif __linux__
#include <sys/socket.h>
#endif
#include <sys/types.h>
#include "usrsctp.h"
namespace rtc {

View File

@ -23,10 +23,6 @@
#include <memory>
#include <thread>
#ifdef _WIN32
#include <winsock2.h>
#endif
using namespace rtc;
using namespace std;
@ -35,12 +31,6 @@ template <class T> weak_ptr<T> make_weak_ptr(shared_ptr<T> 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;
}

View File

@ -23,10 +23,6 @@
#include <memory>
#include <thread>
#ifdef _WIN32
#include <winsock2.h>
#endif
using namespace rtc;
using namespace std;
@ -35,12 +31,6 @@ template <class T> weak_ptr<T> make_weak_ptr(shared_ptr<T> 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
}

View File

@ -23,10 +23,6 @@
#include <memory>
#include <thread>
#ifdef _WIN32
#include <winsock2.h>
#endif
using namespace rtc;
using namespace std;
@ -35,12 +31,6 @@ template <class T> weak_ptr<T> make_weak_ptr(shared_ptr<T> 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
}