Socket Factory has only one function which works for server and client code, and can do tls for both
This commit is contained in:
@ -147,7 +147,7 @@ namespace ix
|
||||
|
||||
bool tls = protocol == "https";
|
||||
std::string errorMsg;
|
||||
_socket = createSocket(tls, errorMsg, _tlsOptions);
|
||||
_socket = createSocket(tls, -1, errorMsg, _tlsOptions);
|
||||
|
||||
if (!_socket)
|
||||
{
|
||||
|
@ -27,6 +27,7 @@
|
||||
namespace ix
|
||||
{
|
||||
std::shared_ptr<Socket> createSocket(bool tls,
|
||||
int fd,
|
||||
std::string& errorMsg,
|
||||
const SocketTLSOptions& tlsOptions)
|
||||
{
|
||||
@ -35,19 +36,19 @@ namespace ix
|
||||
|
||||
if (!tls)
|
||||
{
|
||||
socket = std::make_shared<Socket>();
|
||||
socket = std::make_shared<Socket>(fd);
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef IXWEBSOCKET_USE_TLS
|
||||
#if defined(IXWEBSOCKET_USE_MBED_TLS)
|
||||
socket = std::make_shared<SocketMbedTLS>(tlsOptions);
|
||||
socket = std::make_shared<SocketMbedTLS>(tlsOptions, fd);
|
||||
#elif defined(IXWEBSOCKET_USE_OPEN_SSL)
|
||||
socket = std::make_shared<SocketOpenSSL>(tlsOptions);
|
||||
socket = std::make_shared<SocketOpenSSL>(tlsOptions, fd);
|
||||
#elif defined(_WIN32)
|
||||
socket = std::make_shared<SocketSChannel>(tlsOptions);
|
||||
socket = std::make_shared<SocketSChannel>(tlsOptions, fd);
|
||||
#elif defined(__APPLE__)
|
||||
socket = std::make_shared<SocketAppleSSL>(tlsOptions);
|
||||
socket = std::make_shared<SocketAppleSSL>(tlsOptions, fd);
|
||||
#endif
|
||||
#else
|
||||
errorMsg = "TLS support is not enabled on this platform.";
|
||||
@ -62,17 +63,4 @@ namespace ix
|
||||
|
||||
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;
|
||||
}
|
||||
} // namespace ix
|
||||
|
@ -15,8 +15,7 @@ namespace ix
|
||||
{
|
||||
class Socket;
|
||||
std::shared_ptr<Socket> createSocket(bool tls,
|
||||
int fd,
|
||||
std::string& errorMsg,
|
||||
const SocketTLSOptions& tlsOptions);
|
||||
|
||||
std::shared_ptr<Socket> createSocket(int fd, std::string& errorMsg);
|
||||
} // namespace ix
|
||||
|
@ -270,7 +270,8 @@ namespace ix
|
||||
|
||||
// create socket
|
||||
std::string errorMsg;
|
||||
auto socket = createSocket(clientFd, errorMsg);
|
||||
bool tls = false;
|
||||
auto socket = createSocket(tls, clientFd, errorMsg, _socketTLSOptions);
|
||||
|
||||
if (socket == nullptr)
|
||||
{
|
||||
|
@ -201,8 +201,7 @@ namespace ix
|
||||
return status;
|
||||
}
|
||||
|
||||
WebSocketInitResult WebSocket::connectToSocket(std::shared_ptr<Socket> socket,
|
||||
int timeoutSecs)
|
||||
WebSocketInitResult WebSocket::connectToSocket(std::shared_ptr<Socket> socket, int timeoutSecs)
|
||||
{
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(_configMutex);
|
||||
|
@ -113,8 +113,7 @@ namespace ix
|
||||
static void invokeTrafficTrackerCallback(size_t size, bool incoming);
|
||||
|
||||
// Server
|
||||
WebSocketInitResult connectToSocket(std::shared_ptr<Socket>,
|
||||
int timeoutSecs);
|
||||
WebSocketInitResult connectToSocket(std::shared_ptr<Socket>, int timeoutSecs);
|
||||
|
||||
WebSocketTransport _ws;
|
||||
|
||||
|
@ -148,7 +148,7 @@ namespace ix
|
||||
|
||||
std::string errorMsg;
|
||||
bool tls = protocol == "wss";
|
||||
_socket = createSocket(tls, errorMsg, _socketTLSOptions);
|
||||
_socket = createSocket(tls, -1, errorMsg, _socketTLSOptions);
|
||||
|
||||
if (!_socket)
|
||||
{
|
||||
|
@ -78,14 +78,12 @@ namespace ix
|
||||
int pingTimeoutSecs);
|
||||
|
||||
// Client
|
||||
WebSocketInitResult connectToUrl(
|
||||
const std::string& url,
|
||||
const WebSocketHttpHeaders& headers,
|
||||
int timeoutSecs);
|
||||
WebSocketInitResult connectToUrl(const std::string& url,
|
||||
const WebSocketHttpHeaders& headers,
|
||||
int timeoutSecs);
|
||||
|
||||
// Server
|
||||
WebSocketInitResult connectToSocket(std::shared_ptr<Socket> socket,
|
||||
int timeoutSecs);
|
||||
WebSocketInitResult connectToSocket(std::shared_ptr<Socket> socket, int timeoutSecs);
|
||||
|
||||
PollResult poll();
|
||||
WebSocketSendInfo sendBinary(const std::string& message,
|
||||
|
Reference in New Issue
Block a user