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"
|
|
|
|
|
|
|
|
#if defined(__APPLE__) or defined(__linux__)
|
|
|
|
# ifdef __APPLE__
|
|
|
|
# include <ixwebsocket/IXSocketAppleSSL.h>
|
|
|
|
# else
|
|
|
|
# include <ixwebsocket/IXSocketOpenSSL.h>
|
|
|
|
# endif
|
|
|
|
#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
|
|
|
|
# ifdef __APPLE__
|
2019-03-15 02:37:38 +01:00
|
|
|
socket = std::make_shared<SocketAppleSSL>();
|
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
|
|
|
}
|
|
|
|
}
|