From 05e644b040f6df5847817fa95d48ded249d6dce2 Mon Sep 17 00:00:00 2001 From: Sandu Liviu Catalin Date: Sun, 5 Sep 2021 12:30:49 +0300 Subject: [PATCH] Minor changes and bugfixes to WS client. --- module/PocoLib/Net.cpp | 6 +++--- module/PocoLib/Net.hpp | 10 ++++------ 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/module/PocoLib/Net.cpp b/module/PocoLib/Net.cpp index 5b04e1fd..9f99a9ca 100644 --- a/module/PocoLib/Net.cpp +++ b/module/PocoLib/Net.cpp @@ -56,8 +56,8 @@ void Register_POCO_Net(HSQUIRRELVM vm, Table &) ); // -------------------------------------------------------------------------------------------- ConstTable(vm).Enum(_SC("SqWsSendFlags"), Enumeration(vm) - .Const(_SC("TEXT"), static_cast< SQInteger >(Poco::Net::WebSocket::FRAME_TEXT)) - .Const(_SC("BINARY"), static_cast< SQInteger >(Poco::Net::WebSocket::FRAME_BINARY)) + .Const(_SC("Text"), static_cast< SQInteger >(Poco::Net::WebSocket::FRAME_TEXT)) + .Const(_SC("Binary"), static_cast< SQInteger >(Poco::Net::WebSocket::FRAME_BINARY)) ); // -------------------------------------------------------------------------------------------- ConstTable(vm).Enum(_SC("SqWsStatusCodes"), Enumeration(vm) @@ -76,7 +76,7 @@ void Register_POCO_Net(HSQUIRRELVM vm, Table &) .Const(_SC("ReservedTlsFailure"), static_cast< SQInteger >(Poco::Net::WebSocket::WS_RESERVED_TLS_FAILURE)) ); // -------------------------------------------------------------------------------------------- - ConstTable(vm).Enum(_SC("SqWsSendFlags"), Enumeration(vm) + ConstTable(vm).Enum(_SC("SqWsErrorCodes"), Enumeration(vm) .Const(_SC("NoHandshake"), static_cast< SQInteger >(Poco::Net::WebSocket::WS_ERR_NO_HANDSHAKE)) .Const(_SC("HandshakeNoVersion"), static_cast< SQInteger >(Poco::Net::WebSocket::WS_ERR_HANDSHAKE_NO_VERSION)) .Const(_SC("HandshakeUnsupportedVersion"), static_cast< SQInteger >(Poco::Net::WebSocket::WS_ERR_HANDSHAKE_UNSUPPORTED_VERSION)) diff --git a/module/PocoLib/Net.hpp b/module/PocoLib/Net.hpp index c867c8fb..db658ea4 100644 --- a/module/PocoLib/Net.hpp +++ b/module/PocoLib/Net.hpp @@ -62,7 +62,7 @@ struct WsClient /* -------------------------------------------------------------------------------------------- * Base constructor. */ - WsClient(StackStrF &host, uint16_t port, StackStrF &uri) + WsClient(StackStrF & host, uint16_t port, StackStrF & uri) : mClient(host.ToStr(), port), mRequest(Poco::Net::HTTPRequest::HTTP_GET, uri.ToStr(), Poco::Net::HTTPRequest::HTTP_1_1), mResponse(), mWebSocket(mClient, mRequest, mResponse), mBuffer(0), mFlags(0), mState(0) @@ -79,7 +79,7 @@ struct WsClient /* -------------------------------------------------------------------------------------------- * Sends a Close control frame to the server end of the connection to initiate an orderly shutdown of the connection. */ - void ShutdownWith(SQInteger code, StackStrF &msg) { + void ShutdownWith(SQInteger code, StackStrF & msg) { mWebSocket.shutdown(static_cast< uint16_t >(code), msg.ToStr()); } @@ -95,7 +95,7 @@ struct WsClient * Sends the contents of the given string through the socket as a single frame. * Returns the number of bytes sent, which may be less than the number of bytes specified. */ - SQInteger SendStringFrame(SQInteger flags, StackStrF &str) { + SQInteger SendStringFrame(SQInteger flags, StackStrF & str) { return mWebSocket.sendFrame(str.mPtr, static_cast< int >(str.mLen), static_cast< int >(flags)); } @@ -136,9 +136,7 @@ struct WsClient if (mState != 0) { // Create a string with buffer contents - LightObj obj(SqTypeIdentity< SqBuffer >{}, SqVM(), - const_cast< const SQChar * >(mBuffer.begin()), - static_cast< SQInteger >(mBuffer.sizeBytes())); + LightObj obj(const_cast< const SQChar * >(mBuffer.begin()), static_cast< SQInteger >(mBuffer.sizeBytes()), SqVM()); // Discard buffer contents for next request mBuffer.resize(0); // Return the string object