ws connect mode / add a flag to disable automatic reconnection, not hooked up yet
This commit is contained in:
parent
e15700235e
commit
9ee05bf591
@ -58,6 +58,7 @@ int main(int argc, char** argv)
|
||||
bool compress = false;
|
||||
bool strict = false;
|
||||
bool stress = false;
|
||||
bool disableAutomaticReconnection = false;
|
||||
int port = 8080;
|
||||
int redisPort = 6379;
|
||||
int statsdPort = 8125;
|
||||
@ -87,6 +88,7 @@ int main(int argc, char** argv)
|
||||
|
||||
CLI::App* connectApp = app.add_subcommand("connect", "Connect to a remote server");
|
||||
connectApp->add_option("url", url, "Connection url")->required();
|
||||
connectApp->add_flag("-d", disableAutomaticReconnection, "Disable Automatic Reconnection");
|
||||
|
||||
CLI::App* chatApp = app.add_subcommand("chat", "Group chat");
|
||||
chatApp->add_option("url", url, "Connection url")->required();
|
||||
@ -218,7 +220,7 @@ int main(int argc, char** argv)
|
||||
}
|
||||
else if (app.got_subcommand("connect"))
|
||||
{
|
||||
ret = ix::ws_connect_main(url);
|
||||
ret = ix::ws_connect_main(url, disableAutomaticReconnection);
|
||||
}
|
||||
else if (app.got_subcommand("chat"))
|
||||
{
|
||||
|
2
ws/ws.h
2
ws/ws.h
@ -31,7 +31,7 @@ namespace ix
|
||||
int ws_chat_main(const std::string& url,
|
||||
const std::string& user);
|
||||
|
||||
int ws_connect_main(const std::string& url);
|
||||
int ws_connect_main(const std::string& url, bool disableAutomaticReconnection);
|
||||
|
||||
int ws_receive_main(const std::string& url,
|
||||
bool enablePerMessageDeflate,
|
||||
|
@ -14,7 +14,8 @@ namespace ix
|
||||
class WebSocketConnect
|
||||
{
|
||||
public:
|
||||
WebSocketConnect(const std::string& _url);
|
||||
WebSocketConnect(const std::string& _url,
|
||||
bool disableAutomaticReconnection);
|
||||
|
||||
void subscribe(const std::string& channel);
|
||||
void start();
|
||||
@ -29,10 +30,16 @@ namespace ix
|
||||
void log(const std::string& msg);
|
||||
};
|
||||
|
||||
WebSocketConnect::WebSocketConnect(const std::string& url) :
|
||||
WebSocketConnect::WebSocketConnect(const std::string& url,
|
||||
bool disableAutomaticReconnection) :
|
||||
_url(url)
|
||||
{
|
||||
;
|
||||
if (disableAutomaticReconnection)
|
||||
{
|
||||
std::cout << "Disabling automatic reconnection with "
|
||||
"_webSocket.disableAutomaticReconnection()"
|
||||
" not supported yet" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void WebSocketConnect::log(const std::string& msg)
|
||||
@ -113,10 +120,10 @@ namespace ix
|
||||
_webSocket.send(text);
|
||||
}
|
||||
|
||||
void interactiveMain(const std::string& url)
|
||||
int ws_connect_main(const std::string& url, bool disableAutomaticReconnection)
|
||||
{
|
||||
std::cout << "Type Ctrl-D to exit prompt..." << std::endl;
|
||||
WebSocketConnect webSocketChat(url);
|
||||
WebSocketConnect webSocketChat(url, disableAutomaticReconnection);
|
||||
webSocketChat.start();
|
||||
|
||||
while (true)
|
||||
@ -149,11 +156,7 @@ namespace ix
|
||||
|
||||
std::cout << std::endl;
|
||||
webSocketChat.stop();
|
||||
}
|
||||
|
||||
int ws_connect_main(const std::string& url)
|
||||
{
|
||||
interactiveMain(url);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user