3 Commits
2.2.2 ... 3.0.0

Author SHA1 Message Date
JCash
d5237bbee1 Remove dold include dns.h 2021-05-01 10:13:36 +02:00
JCash
daffff4c06 Updated dmConnectionPool::Dial call for new beta release 2021-04-30 10:58:31 +02:00
VitaliiTihobrazov-Melsoft
0f841f16af fix: the connection must be closed in other states (#41) 2021-04-12 22:45:09 +02:00
2 changed files with 6 additions and 18 deletions

View File

@@ -7,7 +7,6 @@
#include "websocket.h"
#include "script_util.h"
#include <dmsdk/dlib/connection_pool.h>
#include <dmsdk/dlib/dns.h>
#include <dmsdk/dlib/thread.h>
#include <dmsdk/dlib/sslsocket.h>
#include <ctype.h> // isprint et al
@@ -32,7 +31,6 @@ struct WebsocketContext
int m_Timeout;
dmArray<WebsocketConnection*> m_Connections;
dmConnectionPool::HPool m_Pool;
dmDNS::HChannel m_Channel;
uint32_t m_Initialized:1;
} g_Websocket;
@@ -251,10 +249,7 @@ static void CloseConnection(WebsocketConnection* conn)
// we want it to send this message in the polling
if (conn->m_State == STATE_CONNECTED) {
#if defined(HAVE_WSLAY)
// close the connection and immediately transition to the DISCONNECTED
// state
WSL_Close(conn->m_Ctx);
SetState(conn, STATE_DISCONNECTED);
#else
// start disconnecting by closing the WebSocket through the JS API
// we transition to the DISCONNECTED state when we receive the
@@ -264,6 +259,11 @@ static void CloseConnection(WebsocketConnection* conn)
#endif
}
#if defined(HAVE_WSLAY)
// close the connection and immediately transition to the DISCONNECTED
// state
SetState(conn, STATE_DISCONNECTED);
#endif
}
static bool IsConnectionValid(WebsocketConnection* conn)
@@ -527,7 +527,6 @@ static dmExtension::Result AppInitialize(dmExtension::AppParams* params)
g_Websocket.m_BufferSize = dmConfigFile::GetInt(params->m_ConfigFile, "websocket.buffer_size", 64 * 1024);
g_Websocket.m_Timeout = dmConfigFile::GetInt(params->m_ConfigFile, "websocket.socket_timeout", 500 * 1000);
g_Websocket.m_Connections.SetCapacity(4);
g_Websocket.m_Channel = 0;
g_Websocket.m_Pool = 0;
g_Websocket.m_Initialized = 0;
@@ -545,16 +544,6 @@ static dmExtension::Result AppInitialize(dmExtension::AppParams* params)
return dmExtension::RESULT_INIT_ERROR;
}
// We can do without the channel, it will then fallback to the dmSocket::GetHostname (as opposed to dmDNS::GetHostname)
#if defined(HAVE_WSLAY)
dmDNS::Result dns_result = dmDNS::NewChannel(&g_Websocket.m_Channel);
if (dmDNS::RESULT_OK != dns_result)
{
dmLogError("Failed to create DNS channel: %d", dns_result);
}
#endif
g_Websocket.m_Initialized = 1;
return dmExtension::RESULT_OK;
}
@@ -625,7 +614,7 @@ static void ConnectionWorker(void* _conn)
{
WebsocketConnection* conn = (WebsocketConnection*)_conn;
dmSocket::Result sr;
dmConnectionPool::Result pool_result = dmConnectionPool::Dial(g_Websocket.m_Pool, conn->m_Url.m_Hostname, conn->m_Url.m_Port, g_Websocket.m_Channel, conn->m_SSL, g_Websocket.m_Timeout, &conn->m_Connection, &sr);
dmConnectionPool::Result pool_result = dmConnectionPool::Dial(g_Websocket.m_Pool, conn->m_Url.m_Hostname, conn->m_Url.m_Port, conn->m_SSL, g_Websocket.m_Timeout, &conn->m_Connection, &sr);
if (dmConnectionPool::RESULT_OK != pool_result)
{
CLOSE_CONN("Failed to open connection: %s", dmSocket::ResultToString(sr));

View File

@@ -21,7 +21,6 @@
#include <dmsdk/dlib/connection_pool.h>
#include <dmsdk/dlib/socket.h>
#include <dmsdk/dlib/dns.h>
#include <dmsdk/dlib/uri.h>
#include <dmsdk/dlib/array.h>
#include <dmsdk/dlib/thread.h>