close and stop with code and reason + docker = ubuntu xenial

This commit is contained in:
Benjamin Sergeant
2019-05-10 20:47:13 -07:00
parent 186c8fbb62
commit 7f1e70329c
5 changed files with 420 additions and 7 deletions

View File

@ -142,9 +142,10 @@ namespace ix
_thread = std::thread(&WebSocket::run, this);
}
void WebSocket::stop()
void WebSocket::stop(uint16_t code,
const std::string& reason)
{
close();
close(code, reason);
if (_thread.joinable())
{
@ -212,9 +213,10 @@ namespace ix
return getReadyState() == ReadyState::Closing;
}
void WebSocket::close()
void WebSocket::close(uint16_t code,
const std::string& reason)
{
_ws.close();
_ws.close(code, reason);
}
void WebSocket::checkConnection(bool firstConnectionAttempt)

View File

@ -99,8 +99,10 @@ namespace ix
// Run asynchronously, by calling start and stop.
void start();
// stop is synchronous
void stop();
void stop(uint16_t code = 1000,
const std::string& reason = "Normal closure");
// Run in blocking mode, by connecting first manually, and then calling run.
WebSocketInitResult connect(int timeoutSecs);
@ -112,7 +114,9 @@ namespace ix
WebSocketSendInfo sendText(const std::string& text,
const OnProgressCallback& onProgressCallback = nullptr);
WebSocketSendInfo ping(const std::string& text);
void close();
void close(uint16_t code = 1000,
const std::string& reason = "Normal closure");
void setOnMessageCallback(const OnMessageCallback& callback);
static void setTrafficTrackerCallback(const OnTrafficTrackerCallback& callback);