2019-03-01 06:54:03 +01:00
|
|
|
/*
|
|
|
|
* IXSocketFactory.cpp
|
|
|
|
* Author: Benjamin Sergeant
|
|
|
|
* Copyright (c) 2019 Machine Zone, Inc. All rights reserved.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "IXSocketFactory.h"
|
|
|
|
|
2019-04-16 17:51:57 +02:00
|
|
|
#ifdef IXWEBSOCKET_USE_TLS
|
|
|
|
|
2019-06-02 02:41:48 +02:00
|
|
|
# ifdef IXWEBSOCKET_USE_MBED_TLS
|
|
|
|
# include <ixwebsocket/IXSocketMbedTLS.h>
|
|
|
|
# elif __APPLE__
|
2019-03-01 06:54:03 +01:00
|
|
|
# include <ixwebsocket/IXSocketAppleSSL.h>
|
2019-04-16 17:51:57 +02:00
|
|
|
# elif defined(_WIN32)
|
|
|
|
# include <ixwebsocket/IXSocketSChannel.h>
|
2019-06-02 02:41:48 +02:00
|
|
|
# elif defined(IXWEBSOCKET_USE_OPEN_SSL)
|
2019-03-01 06:54:03 +01:00
|
|
|
# include <ixwebsocket/IXSocketOpenSSL.h>
|
|
|
|
# endif
|
2019-04-16 17:51:57 +02:00
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
#include <ixwebsocket/IXSocket.h>
|
|
|
|
|
2019-03-01 06:54:03 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
namespace ix
|
|
|
|
{
|
|
|
|
std::shared_ptr<Socket> createSocket(bool tls,
|
|
|
|
std::string& errorMsg)
|
|
|
|
{
|
|
|
|
errorMsg.clear();
|
2019-03-15 02:37:38 +01:00
|
|
|
std::shared_ptr<Socket> socket;
|
2019-03-01 06:54:03 +01:00
|
|
|
|
|
|
|
if (!tls)
|
|
|
|
{
|
2019-03-15 02:37:38 +01:00
|
|
|
socket = std::make_shared<Socket>();
|
2019-03-01 06:54:03 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
#ifdef IXWEBSOCKET_USE_TLS
|
2019-06-02 02:41:48 +02:00
|
|
|
# if defined(IXWEBSOCKET_USE_MBED_TLS)
|
|
|
|
socket = std::make_shared<SocketMbedTLS>();
|
|
|
|
# elif defined(__APPLE__)
|
2019-03-15 02:37:38 +01:00
|
|
|
socket = std::make_shared<SocketAppleSSL>();
|
2019-04-16 17:51:57 +02:00
|
|
|
# elif defined(_WIN32)
|
|
|
|
socket = std::make_shared<SocketSChannel>();
|
2019-03-01 06:54:03 +01:00
|
|
|
# else
|
2019-03-15 02:37:38 +01:00
|
|
|
socket = std::make_shared<SocketOpenSSL>();
|
2019-03-01 06:54:03 +01:00
|
|
|
# endif
|
|
|
|
#else
|
|
|
|
errorMsg = "TLS support is not enabled on this platform.";
|
|
|
|
return nullptr;
|
|
|
|
#endif
|
|
|
|
}
|
2019-03-15 02:37:38 +01:00
|
|
|
|
|
|
|
if (!socket->init(errorMsg))
|
|
|
|
{
|
|
|
|
socket.reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
return socket;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::shared_ptr<Socket> createSocket(int fd,
|
|
|
|
std::string& errorMsg)
|
|
|
|
{
|
|
|
|
errorMsg.clear();
|
|
|
|
|
|
|
|
std::shared_ptr<Socket> socket = std::make_shared<Socket>(fd);
|
|
|
|
if (!socket->init(errorMsg))
|
|
|
|
{
|
|
|
|
socket.reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
return socket;
|
2019-03-01 06:54:03 +01:00
|
|
|
}
|
|
|
|
}
|