minor improvements (#66)

* minor improvements

* fix build

* improve tests code
This commit is contained in:
Dimon4eg 2019-05-11 22:20:58 +03:00 committed by Benjamin Sergeant
parent 4934f5846b
commit 2254421ead
8 changed files with 21 additions and 30 deletions

View File

@ -148,6 +148,8 @@ namespace ix
if (_thread.joinable()) if (_thread.joinable())
{ {
// wait until working thread will exit
// it will exit after close operation is finished
_stop = true; _stop = true;
_thread.join(); _thread.join();
_stop = false; _stop = false;
@ -361,10 +363,10 @@ namespace ix
} }
} }
WebSocketSendInfo WebSocket::send(const std::string& text, WebSocketSendInfo WebSocket::send(const std::string& data,
const OnProgressCallback& onProgressCallback) const OnProgressCallback& onProgressCallback)
{ {
return sendMessage(text, SendMessageKind::Binary, onProgressCallback); return sendMessage(data, SendMessageKind::Binary, onProgressCallback);
} }
WebSocketSendInfo WebSocket::sendText(const std::string& text, WebSocketSendInfo WebSocket::sendText(const std::string& text,

View File

@ -106,7 +106,8 @@ namespace ix
WebSocketInitResult connect(int timeoutSecs); WebSocketInitResult connect(int timeoutSecs);
void run(); void run();
WebSocketSendInfo send(const std::string& text, // send binary data
WebSocketSendInfo send(const std::string& data,
const OnProgressCallback& onProgressCallback = nullptr); const OnProgressCallback& onProgressCallback = nullptr);
WebSocketSendInfo sendText(const std::string& text, WebSocketSendInfo sendText(const std::string& text,
const OnProgressCallback& onProgressCallback = nullptr); const OnProgressCallback& onProgressCallback = nullptr);

View File

@ -6,9 +6,6 @@
#pragma once #pragma once
#include <string>
#include <iostream>
namespace ix namespace ix
{ {
struct WebSocketSendInfo struct WebSocketSendInfo

View File

@ -719,7 +719,7 @@ namespace ix
bool compress, bool compress,
const OnProgressCallback& onProgressCallback) const OnProgressCallback& onProgressCallback)
{ {
if (_readyState == CLOSING || _readyState == CLOSED) if (_readyState != OPEN)
{ {
return WebSocketSendInfo(); return WebSocketSendInfo();
} }

View File

@ -4,7 +4,6 @@
* Copyright (c) 2019 Machine Zone, Inc. All rights reserved. * Copyright (c) 2019 Machine Zone, Inc. All rights reserved.
*/ */
#include "../IXSetThreadName.h" #include "../IXSetThreadName.h"
#include <iostream>
#include <Windows.h> #include <Windows.h>
namespace ix namespace ix

View File

@ -27,15 +27,6 @@ namespace ix
struct Logger struct Logger
{ {
public: public:
Logger& operator<<(const std::string& msg)
{
std::lock_guard<std::mutex> lock(_mutex);
std::cerr << msg;
std::cerr << std::endl;
return *this;
}
template <typename T> template <typename T>
Logger& operator<<(T const& obj) Logger& operator<<(T const& obj)
{ {

View File

@ -109,38 +109,38 @@ TEST_CASE("websocket_connections", "[websocket]")
{ {
SECTION("Try to connect to invalid servers.") SECTION("Try to connect to invalid servers.")
{ {
IXWebSocketTestConnectionDisconnection chatA; IXWebSocketTestConnectionDisconnection test;
chatA.start(GOOGLE_URL); test.start(GOOGLE_URL);
ix::msleep(1000); ix::msleep(1000);
chatA.stop(); test.stop();
chatA.start(UNKNOWN_URL); test.start(UNKNOWN_URL);
ix::msleep(1000); ix::msleep(1000);
chatA.stop(); test.stop();
} }
SECTION("Try to connect and disconnect with different timing, not enough time to succesfully connect") SECTION("Try to connect and disconnect with different timing, not enough time to succesfully connect")
{ {
IXWebSocketTestConnectionDisconnection chatA; IXWebSocketTestConnectionDisconnection test;
for (int i = 0; i < 50; ++i) for (int i = 0; i < 50; ++i)
{ {
log(std::string("Run: ") + std::to_string(i)); log(std::string("Run: ") + std::to_string(i));
chatA.start(WEBSOCKET_DOT_ORG_URL); test.start(WEBSOCKET_DOT_ORG_URL);
ix::msleep(i); ix::msleep(i);
chatA.stop(); test.stop();
} }
} }
SECTION("Try to connect and disconnect with different timing, from not enough time to successfull connect") /*SECTION("Try to connect and disconnect with different timing, from not enough time to successfull connect")
{ {
IXWebSocketTestConnectionDisconnection chatA; IXWebSocketTestConnectionDisconnection test;
for (int i = 0; i < 20; ++i) for (int i = 0; i < 20; ++i)
{ {
log(std::string("Run: ") + std::to_string(i)); log(std::string("Run: ") + std::to_string(i));
chatA.start(WEBSOCKET_DOT_ORG_URL); test.start(WEBSOCKET_DOT_ORG_URL);
ix::msleep(i*50); ix::msleep(i*50);
chatA.stop(); test.stop();
} }
} }*/
} }

View File

@ -14,6 +14,7 @@
#include "nlohmann/json.hpp" #include "nlohmann/json.hpp"
#include <sstream> #include <sstream>
#include <iostream>
namespace snake namespace snake
{ {