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-09-23 03:06:15 +02:00
|
|
|
#ifdef IXWEBSOCKET_USE_MBED_TLS
|
|
|
|
#include <ixwebsocket/IXSocketMbedTLS.h>
|
|
|
|
#elif defined(_WIN32)
|
|
|
|
#include <ixwebsocket/IXSocketSChannel.h>
|
|
|
|
#elif defined(IXWEBSOCKET_USE_OPEN_SSL)
|
|
|
|
#include <ixwebsocket/IXSocketOpenSSL.h>
|
2019-09-30 00:34:58 +02:00
|
|
|
#elif __APPLE__
|
|
|
|
#include <ixwebsocket/IXSocketAppleSSL.h>
|
2019-09-23 03:06:15 +02:00
|
|
|
#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,
|
2019-10-01 07:06:46 +02:00
|
|
|
int fd,
|
2019-09-23 03:06:15 +02:00
|
|
|
std::string& errorMsg,
|
|
|
|
const SocketTLSOptions& tlsOptions)
|
2019-03-01 06:54:03 +01:00
|
|
|
{
|
2019-11-20 20:12:24 +01:00
|
|
|
(void) tlsOptions;
|
2019-03-01 06:54:03 +01:00
|
|
|
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-10-01 07:06:46 +02:00
|
|
|
socket = std::make_shared<Socket>(fd);
|
2019-03-01 06:54:03 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
#ifdef IXWEBSOCKET_USE_TLS
|
2019-09-23 03:06:15 +02:00
|
|
|
#if defined(IXWEBSOCKET_USE_MBED_TLS)
|
2019-10-01 07:06:46 +02:00
|
|
|
socket = std::make_shared<SocketMbedTLS>(tlsOptions, fd);
|
2019-09-30 00:34:58 +02:00
|
|
|
#elif defined(IXWEBSOCKET_USE_OPEN_SSL)
|
2019-10-01 07:06:46 +02:00
|
|
|
socket = std::make_shared<SocketOpenSSL>(tlsOptions, fd);
|
2019-09-23 03:06:15 +02:00
|
|
|
#elif defined(_WIN32)
|
2019-10-01 07:06:46 +02:00
|
|
|
socket = std::make_shared<SocketSChannel>(tlsOptions, fd);
|
2019-09-30 00:34:58 +02:00
|
|
|
#elif defined(__APPLE__)
|
2019-10-01 07:06:46 +02:00
|
|
|
socket = std::make_shared<SocketAppleSSL>(tlsOptions, fd);
|
2019-09-23 03:06:15 +02:00
|
|
|
#endif
|
2019-03-01 06:54:03 +01:00
|
|
|
#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;
|
|
|
|
}
|
2019-09-23 03:06:15 +02:00
|
|
|
} // namespace ix
|