4 Commits
2.2.1 ... 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
Björn Ritzl
97cca427d7 Reduced thread name length (#39)
pthread_setname_np() restricts thread name length to 16 characters.
2021-03-18 20:41:03 +01:00
2 changed files with 7 additions and 19 deletions

View File

@@ -7,7 +7,6 @@
#include "websocket.h" #include "websocket.h"
#include "script_util.h" #include "script_util.h"
#include <dmsdk/dlib/connection_pool.h> #include <dmsdk/dlib/connection_pool.h>
#include <dmsdk/dlib/dns.h>
#include <dmsdk/dlib/thread.h> #include <dmsdk/dlib/thread.h>
#include <dmsdk/dlib/sslsocket.h> #include <dmsdk/dlib/sslsocket.h>
#include <ctype.h> // isprint et al #include <ctype.h> // isprint et al
@@ -32,7 +31,6 @@ struct WebsocketContext
int m_Timeout; int m_Timeout;
dmArray<WebsocketConnection*> m_Connections; dmArray<WebsocketConnection*> m_Connections;
dmConnectionPool::HPool m_Pool; dmConnectionPool::HPool m_Pool;
dmDNS::HChannel m_Channel;
uint32_t m_Initialized:1; uint32_t m_Initialized:1;
} g_Websocket; } g_Websocket;
@@ -251,10 +249,7 @@ static void CloseConnection(WebsocketConnection* conn)
// we want it to send this message in the polling // we want it to send this message in the polling
if (conn->m_State == STATE_CONNECTED) { if (conn->m_State == STATE_CONNECTED) {
#if defined(HAVE_WSLAY) #if defined(HAVE_WSLAY)
// close the connection and immediately transition to the DISCONNECTED
// state
WSL_Close(conn->m_Ctx); WSL_Close(conn->m_Ctx);
SetState(conn, STATE_DISCONNECTED);
#else #else
// start disconnecting by closing the WebSocket through the JS API // start disconnecting by closing the WebSocket through the JS API
// we transition to the DISCONNECTED state when we receive the // we transition to the DISCONNECTED state when we receive the
@@ -264,6 +259,11 @@ static void CloseConnection(WebsocketConnection* conn)
#endif #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) 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_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_Timeout = dmConfigFile::GetInt(params->m_ConfigFile, "websocket.socket_timeout", 500 * 1000);
g_Websocket.m_Connections.SetCapacity(4); g_Websocket.m_Connections.SetCapacity(4);
g_Websocket.m_Channel = 0;
g_Websocket.m_Pool = 0; g_Websocket.m_Pool = 0;
g_Websocket.m_Initialized = 0; g_Websocket.m_Initialized = 0;
@@ -545,16 +544,6 @@ static dmExtension::Result AppInitialize(dmExtension::AppParams* params)
return dmExtension::RESULT_INIT_ERROR; 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; g_Websocket.m_Initialized = 1;
return dmExtension::RESULT_OK; return dmExtension::RESULT_OK;
} }
@@ -625,7 +614,7 @@ static void ConnectionWorker(void* _conn)
{ {
WebsocketConnection* conn = (WebsocketConnection*)_conn; WebsocketConnection* conn = (WebsocketConnection*)_conn;
dmSocket::Result sr; 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) if (dmConnectionPool::RESULT_OK != pool_result)
{ {
CLOSE_CONN("Failed to open connection: %s", dmSocket::ResultToString(sr)); CLOSE_CONN("Failed to open connection: %s", dmSocket::ResultToString(sr));
@@ -819,7 +808,7 @@ static dmExtension::Result OnUpdate(dmExtension::Params* params)
emscripten_websocket_set_onclose_callback(ws, conn, Emscripten_WebSocketOnClose); emscripten_websocket_set_onclose_callback(ws, conn, Emscripten_WebSocketOnClose);
emscripten_websocket_set_onmessage_callback(ws, conn, Emscripten_WebSocketOnMessage); emscripten_websocket_set_onmessage_callback(ws, conn, Emscripten_WebSocketOnMessage);
#else #else
conn->m_ConnectionThread = dmThread::New((dmThread::ThreadStart)ConnectionWorker, 0x80000, conn, "WebSocketConnectionThread"); conn->m_ConnectionThread = dmThread::New((dmThread::ThreadStart)ConnectionWorker, 0x80000, conn, "WSConnect");
#endif #endif
SetState(conn, STATE_CONNECTING); SetState(conn, STATE_CONNECTING);
} }

View File

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