Add explicite WebSocket::sendBinary
New headers + WebSocketMessage class to hold message data, still not used across the board
This commit is contained in:
parent
051c34bc5d
commit
23cf4bd59b
@ -16,6 +16,7 @@
|
|||||||
#include "IXWebSocketPerMessageDeflateOptions.h"
|
#include "IXWebSocketPerMessageDeflateOptions.h"
|
||||||
#include "IXWebSocketSendInfo.h"
|
#include "IXWebSocketSendInfo.h"
|
||||||
#include "IXWebSocketTransport.h"
|
#include "IXWebSocketTransport.h"
|
||||||
|
#include "IXWebSocketMessage.h"
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <string>
|
#include <string>
|
||||||
@ -32,46 +33,6 @@ namespace ix
|
|||||||
Closed = 3
|
Closed = 3
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class WebSocketMessageType
|
|
||||||
{
|
|
||||||
Message = 0,
|
|
||||||
Open = 1,
|
|
||||||
Close = 2,
|
|
||||||
Error = 3,
|
|
||||||
Ping = 4,
|
|
||||||
Pong = 5,
|
|
||||||
Fragment = 6
|
|
||||||
};
|
|
||||||
|
|
||||||
struct WebSocketOpenInfo
|
|
||||||
{
|
|
||||||
std::string uri;
|
|
||||||
WebSocketHttpHeaders headers;
|
|
||||||
|
|
||||||
WebSocketOpenInfo(const std::string& u = std::string(),
|
|
||||||
const WebSocketHttpHeaders& h = WebSocketHttpHeaders())
|
|
||||||
: uri(u)
|
|
||||||
, headers(h)
|
|
||||||
{
|
|
||||||
;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
struct WebSocketCloseInfo
|
|
||||||
{
|
|
||||||
uint16_t code;
|
|
||||||
std::string reason;
|
|
||||||
bool remote;
|
|
||||||
|
|
||||||
WebSocketCloseInfo(uint16_t c = 0, const std::string& r = std::string(), bool rem = false)
|
|
||||||
: code(c)
|
|
||||||
, reason(r)
|
|
||||||
, remote(rem)
|
|
||||||
{
|
|
||||||
;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
using OnMessageCallback = std::function<void(WebSocketMessageType,
|
using OnMessageCallback = std::function<void(WebSocketMessageType,
|
||||||
const std::string&,
|
const std::string&,
|
||||||
size_t wireSize,
|
size_t wireSize,
|
||||||
@ -169,7 +130,7 @@ namespace ix
|
|||||||
bool _enablePong;
|
bool _enablePong;
|
||||||
static const bool kDefaultEnablePong;
|
static const bool kDefaultEnablePong;
|
||||||
|
|
||||||
// Optional ping and ping timeout
|
// Optional ping and pong timeout
|
||||||
int _pingIntervalSecs;
|
int _pingIntervalSecs;
|
||||||
int _pingTimeoutSecs;
|
int _pingTimeoutSecs;
|
||||||
static const int kDefaultPingIntervalSecs;
|
static const int kDefaultPingIntervalSecs;
|
||||||
|
25
ixwebsocket/IXWebSocketCloseInfo.h
Normal file
25
ixwebsocket/IXWebSocketCloseInfo.h
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
/*
|
||||||
|
* IXWebSocketCloseInfo.h
|
||||||
|
* Author: Benjamin Sergeant
|
||||||
|
* Copyright (c) 2017-2019 Machine Zone, Inc. All rights reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace ix
|
||||||
|
{
|
||||||
|
struct WebSocketCloseInfo
|
||||||
|
{
|
||||||
|
uint16_t code;
|
||||||
|
std::string reason;
|
||||||
|
bool remote;
|
||||||
|
|
||||||
|
WebSocketCloseInfo(uint16_t c = 0, const std::string& r = std::string(), bool rem = false)
|
||||||
|
: code(c)
|
||||||
|
, reason(r)
|
||||||
|
, remote(rem)
|
||||||
|
{
|
||||||
|
;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
31
ixwebsocket/IXWebSocketMessage.h
Normal file
31
ixwebsocket/IXWebSocketMessage.h
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* IXWebSocketMessage.h
|
||||||
|
* Author: Benjamin Sergeant
|
||||||
|
* Copyright (c) 2017-2019 Machine Zone, Inc. All rights reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "IXWebSocketMessageType.h"
|
||||||
|
#include "IXWebSocketErrorInfo.h"
|
||||||
|
#include "IXWebSocketOpenInfo.h"
|
||||||
|
#include "IXWebSocketCloseInfo.h"
|
||||||
|
#include <string>
|
||||||
|
#include <memory>
|
||||||
|
#include <thread>
|
||||||
|
|
||||||
|
namespace ix
|
||||||
|
{
|
||||||
|
struct WebSocketMessage
|
||||||
|
{
|
||||||
|
WebSocketMessageType type;
|
||||||
|
std::string str;
|
||||||
|
size_t wireSize;
|
||||||
|
WebSocketErrorInfo errorInfo;
|
||||||
|
WebSocketOpenInfo openInfo;
|
||||||
|
WebSocketCloseInfo closeInfo;
|
||||||
|
bool binary;
|
||||||
|
};
|
||||||
|
|
||||||
|
using WebSocketMessagePtr = std::shared_ptr<WebSocketMessage>;
|
||||||
|
} // namespace ix
|
@ -30,24 +30,12 @@ namespace ix
|
|||||||
void poll(int count = 512);
|
void poll(int count = 512);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
struct Message
|
WebSocketMessagePtr popMessage();
|
||||||
{
|
|
||||||
WebSocketMessageType type;
|
|
||||||
std::string str;
|
|
||||||
size_t wireSize;
|
|
||||||
WebSocketErrorInfo errorInfo;
|
|
||||||
WebSocketOpenInfo openInfo;
|
|
||||||
WebSocketCloseInfo closeInfo;
|
|
||||||
};
|
|
||||||
|
|
||||||
using MessagePtr = std::shared_ptr<Message>;
|
|
||||||
|
|
||||||
MessagePtr popMessage();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
WebSocket* _websocket = nullptr;
|
WebSocket* _websocket = nullptr;
|
||||||
OnMessageCallback _onMessageUserCallback;
|
OnMessageCallback _onMessageUserCallback;
|
||||||
std::mutex _messagesMutex;
|
std::mutex _messagesMutex;
|
||||||
std::list<MessagePtr> _messages;
|
std::list<WebSocketMessagePtr> _messages;
|
||||||
};
|
};
|
||||||
} // namespace ix
|
} // namespace ix
|
||||||
|
21
ixwebsocket/IXWebSocketMessageType.h
Normal file
21
ixwebsocket/IXWebSocketMessageType.h
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
/*
|
||||||
|
* IXWebSocketMessageType.h
|
||||||
|
* Author: Benjamin Sergeant
|
||||||
|
* Copyright (c) 2017-2019 Machine Zone, Inc. All rights reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace ix
|
||||||
|
{
|
||||||
|
enum class WebSocketMessageType
|
||||||
|
{
|
||||||
|
Message = 0,
|
||||||
|
Open = 1,
|
||||||
|
Close = 2,
|
||||||
|
Error = 3,
|
||||||
|
Ping = 4,
|
||||||
|
Pong = 5,
|
||||||
|
Fragment = 6
|
||||||
|
};
|
||||||
|
}
|
24
ixwebsocket/IXWebSocketOpenInfo.h
Normal file
24
ixwebsocket/IXWebSocketOpenInfo.h
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
/*
|
||||||
|
* IXWebSocketOpenInfo.h
|
||||||
|
* Author: Benjamin Sergeant
|
||||||
|
* Copyright (c) 2017-2019 Machine Zone, Inc. All rights reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace ix
|
||||||
|
{
|
||||||
|
struct WebSocketOpenInfo
|
||||||
|
{
|
||||||
|
std::string uri;
|
||||||
|
WebSocketHttpHeaders headers;
|
||||||
|
|
||||||
|
WebSocketOpenInfo(const std::string& u = std::string(),
|
||||||
|
const WebSocketHttpHeaders& h = WebSocketHttpHeaders())
|
||||||
|
: uri(u)
|
||||||
|
, headers(h)
|
||||||
|
{
|
||||||
|
;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user