add -6 option to ws echo_server / cf #148
This commit is contained in:
parent
3c27228585
commit
f3d562ff02
@ -86,7 +86,7 @@ namespace ix
|
||||
server.sin_family = _addressFamily;
|
||||
server.sin_port = htons(_port);
|
||||
|
||||
if (inet_pton(_addressFamily, _host.c_str(), &server.sin_addr.s_addr) < 0)
|
||||
if (inet_pton(_addressFamily, _host.c_str(), &server.sin_addr.s_addr) <= 0)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << "SocketServer::listen() error calling inet_pton "
|
||||
@ -96,7 +96,7 @@ namespace ix
|
||||
return std::make_pair(false, ss.str());
|
||||
}
|
||||
|
||||
if (bind(_serverFd, (struct sockaddr*) &server, sizeof(server)) < 0)
|
||||
if (bind(_serverFd, (struct sockaddr*) &server, sizeof(server)) <= 0)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << "SocketServer::listen() error calling bind "
|
||||
|
@ -42,6 +42,8 @@ namespace ix
|
||||
// Get all the connected clients
|
||||
std::set<std::shared_ptr<WebSocket>> getClients();
|
||||
|
||||
const static int kDefaultHandShakeTimeoutSecs;
|
||||
|
||||
private:
|
||||
// Member variables
|
||||
int _handshakeTimeoutSecs;
|
||||
@ -52,7 +54,6 @@ namespace ix
|
||||
std::mutex _clientsMutex;
|
||||
std::set<std::shared_ptr<WebSocket>> _clients;
|
||||
|
||||
const static int kDefaultHandShakeTimeoutSecs;
|
||||
const static bool kDefaultEnablePong;
|
||||
|
||||
// Methods
|
||||
|
@ -94,6 +94,7 @@ int main(int argc, char** argv)
|
||||
bool disableAutomaticReconnection = false;
|
||||
bool disablePerMessageDeflate = false;
|
||||
bool greetings = false;
|
||||
bool ipv6 = false;
|
||||
bool binaryMode = false;
|
||||
bool redirect = false;
|
||||
bool version = false;
|
||||
@ -171,6 +172,7 @@ int main(int argc, char** argv)
|
||||
echoServerApp->add_option("--port", port, "Port");
|
||||
echoServerApp->add_option("--host", hostname, "Hostname");
|
||||
echoServerApp->add_flag("-g", greetings, "Verbose");
|
||||
echoServerApp->add_flag("-6", ipv6, "IpV6");
|
||||
addTLSOptions(echoServerApp);
|
||||
|
||||
CLI::App* broadcastServerApp = app.add_subcommand("broadcast_server", "Broadcasting server");
|
||||
@ -390,7 +392,7 @@ int main(int argc, char** argv)
|
||||
}
|
||||
else if (app.got_subcommand("echo_server"))
|
||||
{
|
||||
ret = ix::ws_echo_server_main(port, greetings, hostname, tlsOptions);
|
||||
ret = ix::ws_echo_server_main(port, greetings, hostname, tlsOptions, ipv6);
|
||||
}
|
||||
else if (app.got_subcommand("broadcast_server"))
|
||||
{
|
||||
|
4
ws/ws.h
4
ws/ws.h
@ -29,7 +29,9 @@ namespace ix
|
||||
int ws_echo_server_main(int port,
|
||||
bool greetings,
|
||||
const std::string& hostname,
|
||||
const ix::SocketTLSOptions& tlsOptions);
|
||||
const ix::SocketTLSOptions& tlsOptions,
|
||||
bool ipv6);
|
||||
|
||||
int ws_broadcast_server_main(int port,
|
||||
const std::string& hostname,
|
||||
const ix::SocketTLSOptions& tlsOptions);
|
||||
|
@ -5,6 +5,7 @@
|
||||
*/
|
||||
|
||||
#include <ixwebsocket/IXWebSocketServer.h>
|
||||
#include <ixwebsocket/IXNetSystem.h>
|
||||
#include <spdlog/spdlog.h>
|
||||
#include <sstream>
|
||||
|
||||
@ -13,11 +14,18 @@ namespace ix
|
||||
int ws_echo_server_main(int port,
|
||||
bool greetings,
|
||||
const std::string& hostname,
|
||||
const ix::SocketTLSOptions& tlsOptions)
|
||||
const ix::SocketTLSOptions& tlsOptions,
|
||||
bool ipv6)
|
||||
{
|
||||
spdlog::info("Listening on {}:{}", hostname, port);
|
||||
|
||||
ix::WebSocketServer server(port, hostname);
|
||||
ix::WebSocketServer server(port,
|
||||
hostname,
|
||||
SocketServer::kDefaultTcpBacklog,
|
||||
SocketServer::kDefaultMaxConnections,
|
||||
WebSocketServer::kDefaultHandShakeTimeoutSecs,
|
||||
(ipv6) ? AF_INET6 : AF_INET);
|
||||
|
||||
server.setTLSOptions(tlsOptions);
|
||||
|
||||
server.setOnConnectionCallback(
|
||||
|
Loading…
Reference in New Issue
Block a user