diff --git a/ixwebsocket/IXSocketServer.cpp b/ixwebsocket/IXSocketServer.cpp index a6344e27..56012e88 100644 --- a/ixwebsocket/IXSocketServer.cpp +++ b/ixwebsocket/IXSocketServer.cpp @@ -71,9 +71,11 @@ namespace ix (char*) &enable, sizeof(enable)) < 0) { std::stringstream ss; - ss << "SocketServer::listen() error calling setsockopt(SO_REUSEADDR): " - << strerror(errno); + ss << "SocketServer::listen() error calling setsockopt(SO_REUSEADDR) " + << "at address " << _host << ":" << _port + << " : " << strerror(Socket::getErrno()); + ::close(_serverFd); return std::make_pair(false, ss.str()); } @@ -93,21 +95,25 @@ namespace ix if (bind(_serverFd, (struct sockaddr *)&server, sizeof(server)) < 0) { std::stringstream ss; - ss << "SocketServer::listen() error calling bind: " - << strerror(Socket::getErrno()); + ss << "SocketServer::listen() error calling bind " + << "at address " << _host << ":" << _port + << " : " << strerror(Socket::getErrno()); + ::close(_serverFd); return std::make_pair(false, ss.str()); } - /* - * Listen for connections. Specify the tcp backlog. - */ - if (::listen(_serverFd, _backlog) != 0) + // + // Listen for connections. Specify the tcp backlog. + // + if (::listen(_serverFd, _backlog) < 0) { std::stringstream ss; - ss << "SocketServer::listen() error calling listen: " - << strerror(Socket::getErrno()); + ss << "SocketServer::listen() error calling listen " + << "at address " << _host << ":" << _port + << " : " << strerror(Socket::getErrno()); + ::close(_serverFd); return std::make_pair(false, ss.str()); } @@ -136,6 +142,7 @@ namespace ix _stop = false; _conditionVariable.notify_one(); + ::close(_serverFd); } void SocketServer::run() diff --git a/ixwebsocket/IXWebSocketTransport.cpp b/ixwebsocket/IXWebSocketTransport.cpp index e3c5b287..7ae28b8c 100644 --- a/ixwebsocket/IXWebSocketTransport.cpp +++ b/ixwebsocket/IXWebSocketTransport.cpp @@ -162,7 +162,9 @@ namespace ix { if (pollResult == PollResultType_Timeout) { - sendPing(kHeartBeatPingMessage); + std::stringstream ss; + ss << kHeartBeatPingMessage << "::" << _heartBeatPeriod << "s"; + sendPing(ss.str()); return; } diff --git a/test/IXWebSocketHeartBeatTest.cpp b/test/IXWebSocketHeartBeatTest.cpp index 52f37175..87bf0012 100644 --- a/test/IXWebSocketHeartBeatTest.cpp +++ b/test/IXWebSocketHeartBeatTest.cpp @@ -72,11 +72,11 @@ namespace log(std::string("Connecting to url: ") + url); _webSocket.setOnMessageCallback( - [this](ix::WebSocketMessageType messageType, - const std::string& str, - size_t wireSize, - const ix::WebSocketErrorInfo& error, - const ix::WebSocketOpenInfo& openInfo, + [](ix::WebSocketMessageType messageType, + const std::string& str, + size_t wireSize, + const ix::WebSocketErrorInfo& error, + const ix::WebSocketOpenInfo& openInfo, const ix::WebSocketCloseInfo& closeInfo) { std::stringstream ss; diff --git a/test/IXWebSocketTestConnectionDisconnection.cpp b/test/IXWebSocketTestConnectionDisconnection.cpp index 945a2940..d9bf9bc8 100644 --- a/test/IXWebSocketTestConnectionDisconnection.cpp +++ b/test/IXWebSocketTestConnectionDisconnection.cpp @@ -52,12 +52,12 @@ namespace log(std::string("Connecting to url: ") + url); _webSocket.setOnMessageCallback( - [this](ix::WebSocketMessageType messageType, - const std::string& str, - size_t wireSize, - const ix::WebSocketErrorInfo& error, - const ix::WebSocketOpenInfo& openInfo, - const ix::WebSocketCloseInfo& closeInfo) + [](ix::WebSocketMessageType messageType, + const std::string& str, + size_t wireSize, + const ix::WebSocketErrorInfo& error, + const ix::WebSocketOpenInfo& openInfo, + const ix::WebSocketCloseInfo& closeInfo) { std::stringstream ss; if (messageType == ix::WebSocket_MessageType_Open) diff --git a/test/cmd_websocket_chat.cpp b/test/cmd_websocket_chat.cpp index da131df1..b3a49f45 100644 --- a/test/cmd_websocket_chat.cpp +++ b/test/cmd_websocket_chat.cpp @@ -4,11 +4,6 @@ * Copyright (c) 2017 Machine Zone. All rights reserved. */ -// -// Simple chat program that talks to the node.js server at -// websocket_chat_server/broacast-server.js -// - #include #include #include