Files
docker
ixwebsocket
apple
linux
windows
IXCancellationRequest.cpp
IXCancellationRequest.h
IXConnectionState.cpp
IXConnectionState.h
IXDNSLookup.cpp
IXDNSLookup.h
IXHttpClient.cpp
IXHttpClient.h
IXNetSystem.cpp
IXNetSystem.h
IXProgressCallback.h
IXSelectInterrupt.cpp
IXSelectInterrupt.h
IXSelectInterruptEventFd.cpp
IXSelectInterruptEventFd.h
IXSelectInterruptFactory.cpp
IXSelectInterruptFactory.h
IXSelectInterruptPipe.cpp
IXSelectInterruptPipe.h
IXSetThreadName.h
IXSocket.cpp
IXSocket.h
IXSocketAppleSSL.cpp
IXSocketAppleSSL.h
IXSocketConnect.cpp
IXSocketConnect.h
IXSocketFactory.cpp
IXSocketFactory.h
IXSocketOpenSSL.cpp
IXSocketOpenSSL.h
IXSocketSChannel.cpp
IXSocketSChannel.h
IXSocketServer.cpp
IXSocketServer.h
IXUrlParser.cpp
IXUrlParser.h
IXWebSocket.cpp
IXWebSocket.h
IXWebSocketErrorInfo.h
IXWebSocketHandshake.cpp
IXWebSocketHandshake.h
IXWebSocketHttpHeaders.cpp
IXWebSocketHttpHeaders.h
IXWebSocketMessageQueue.cpp
IXWebSocketMessageQueue.h
IXWebSocketPerMessageDeflate.cpp
IXWebSocketPerMessageDeflate.h
IXWebSocketPerMessageDeflateCodec.cpp
IXWebSocketPerMessageDeflateCodec.h
IXWebSocketPerMessageDeflateOptions.cpp
IXWebSocketPerMessageDeflateOptions.h
IXWebSocketSendInfo.h
IXWebSocketServer.cpp
IXWebSocketServer.h
IXWebSocketTransport.cpp
IXWebSocketTransport.h
LUrlParser.cpp
LUrlParser.h
libwshandshake.hpp
test
third_party
ws
.dockerignore
.gitignore
.travis.yml
CMakeLists.txt
DOCKER_VERSION
LICENSE.txt
README.md
appveyor.yml
docker-compose.yml
makefile
IXWebSocket/ixwebsocket/IXWebSocketMessageQueue.h
2019-05-12 20:59:18 +03:00

54 lines
1.2 KiB
C++

/*
* IXWebSocketMessageQueue.h
* Author: Korchynskyi Dmytro
* Copyright (c) 2017-2019 Machine Zone, Inc. All rights reserved.
*/
#pragma once
#include "IXWebSocket.h"
#include <thread>
#include <list>
#include <memory>
namespace ix
{
//
// A helper class to dispatch websocket message callbacks in your thread.
//
class WebSocketMessageQueue
{
public:
WebSocketMessageQueue(WebSocket* websocket = nullptr);
~WebSocketMessageQueue();
void bindWebsocket(WebSocket* websocket);
void setOnMessageCallback(const OnMessageCallback& callback);
void setOnMessageCallback(OnMessageCallback&& callback);
void poll(int count = 512);
protected:
struct Message
{
WebSocketMessageType type;
std::string str;
size_t wireSize;
WebSocketErrorInfo errorInfo;
WebSocketOpenInfo openInfo;
WebSocketCloseInfo closeInfo;
};
using MessagePtr = std::shared_ptr<Message>;
MessagePtr popMessage();
private:
WebSocket* _websocket = nullptr;
OnMessageCallback _onMessageUserCallback;
std::mutex _messagesMutex;
std::list<MessagePtr> _messages;
};
}