add a way to run in blocking more, which is useful for server mode to have N*thread instead of 2N*thread for N connections

This commit is contained in:
Benjamin Sergeant
2019-01-01 21:25:15 -08:00
parent 946d7015a2
commit 1bc5bc7f1c
5 changed files with 54 additions and 18 deletions

View File

@ -72,8 +72,14 @@ namespace ix
void setUrl(const std::string& url);
void setPerMessageDeflateOptions(const WebSocketPerMessageDeflateOptions& perMessageDeflateOptions);
// Run asynchronously, by calling start and stop.
void start();
void stop();
// Run in blocking mode, by connecting first manually, and then calling run.
WebSocketInitResult connect();
void run();
WebSocketSendInfo send(const std::string& text);
WebSocketSendInfo ping(const std::string& text);
void close();
@ -86,12 +92,13 @@ namespace ix
const std::string& getUrl() const;
const WebSocketPerMessageDeflateOptions& getPerMessageDeflateOptions() const;
void enableAutomaticReconnection();
void disableAutomaticReconnection();
private:
void run();
WebSocketSendInfo sendMessage(const std::string& text, bool ping);
WebSocketInitResult connect();
bool isConnected() const;
bool isClosing() const;
void reconnectPerpetuallyIfDisconnected();