From 5b6fdb6526b48f5114b7b5aa2da9a7c72b192c35 Mon Sep 17 00:00:00 2001 From: Benjamin Sergeant Date: Thu, 21 Mar 2019 10:06:59 -0700 Subject: [PATCH] cleanup, remove dead method --- CMakeLists.txt | 2 +- ixwebsocket/IXWebSocketTransport.cpp | 6 ---- ixwebsocket/IXWebSocketTransport.h | 1 - test/CMakeLists.txt | 1 + test/IXSocketConnectTest.cpp | 43 ++++++++++++++++++++++++++++ 5 files changed, 45 insertions(+), 8 deletions(-) create mode 100644 test/IXSocketConnectTest.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index a4ef9882..31f20a40 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,7 +12,7 @@ set (CMAKE_CXX_EXTENSIONS OFF) # -Wshorten-64-to-32 does not work with clang if (NOT WIN32) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic -Wshorten-64-to-32") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic") endif() if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") diff --git a/ixwebsocket/IXWebSocketTransport.cpp b/ixwebsocket/IXWebSocketTransport.cpp index 8eca5b5a..ebafd228 100644 --- a/ixwebsocket/IXWebSocketTransport.cpp +++ b/ixwebsocket/IXWebSocketTransport.cpp @@ -287,12 +287,6 @@ namespace ix } } - void WebSocketTransport::appendToSendBuffer(const std::vector& buffer) - { - std::lock_guard lock(_txbufMutex); - _txbuf.insert(_txbuf.end(), buffer.begin(), buffer.end()); - } - void WebSocketTransport::unmaskReceiveBuffer(const wsheader_type& ws) { if (ws.mask) diff --git a/ixwebsocket/IXWebSocketTransport.h b/ixwebsocket/IXWebSocketTransport.h index 73b7a350..ef31495a 100644 --- a/ixwebsocket/IXWebSocketTransport.h +++ b/ixwebsocket/IXWebSocketTransport.h @@ -174,7 +174,6 @@ namespace ix std::string::const_iterator end, uint64_t message_size, uint8_t masking_key[4]); - void appendToSendBuffer(const std::vector& buffer); unsigned getRandomUnsigned(); void unmaskReceiveBuffer(const wsheader_type& ws); diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 78ed3348..490ed24e 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -29,6 +29,7 @@ set (SOURCES IXDNSLookupTest.cpp IXSocketTest.cpp + IXSocketConnectTest.cpp ) # Some unittest don't work on windows yet diff --git a/test/IXSocketConnectTest.cpp b/test/IXSocketConnectTest.cpp new file mode 100644 index 00000000..1f98173d --- /dev/null +++ b/test/IXSocketConnectTest.cpp @@ -0,0 +1,43 @@ +/* + * IXSocketConnectTest.cpp + * Author: Benjamin Sergeant + * Copyright (c) 2018 Machine Zone. All rights reserved. + */ + +#include "catch.hpp" + +#include "IXTest.h" +#include +#include + +using namespace ix; + + +TEST_CASE("socket_connect", "[net]") +{ + SECTION("Test connecting to a known hostname") + { + std::string errMsg; + int fd = SocketConnect::connect("www.google.com", 80, errMsg, [] { return false; }); + std::cerr << "Error message: " << errMsg << std::endl; + REQUIRE(fd != -1); + } + + SECTION("Test connecting to a non-existing hostname") + { + std::string errMsg; + std::string hostname("12313lhjlkjhopiupoijlkasdckljqwehrlkqjwehraospidcuaposidcasdc"); + int fd = SocketConnect::connect(hostname, 80, errMsg, [] { return false; }); + std::cerr << "Error message: " << errMsg << std::endl; + REQUIRE(fd == -1); + } + + SECTION("Test connecting to a good hostname, with cancellation") + { + std::string errMsg; + // The callback returning true means we are requesting cancellation + int fd = SocketConnect::connect("www.google.com", 80, errMsg, [] { return true; }); + std::cerr << "Error message: " << errMsg << std::endl; + REQUIRE(fd == -1); + } +}