Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V1.0.0 no complication warnings #1

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
21 changes: 16 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
# Change Log for _sockpp_

## [Version 0.8.1](https://github.com/fpagliughi/sockpp/compare/v0.8.0..v0.8.1)
## [Version 1.0.0](https://github.com/fpagliughi/sockpp/compare/v0.8.3..v1.0.0) - (2023-12-17)

Released: 2023-01-30
This is a release of the previous 0.8.x line as the initial, stable API.

## [Version 0.8.3](https://github.com/fpagliughi/sockpp/compare/v0.8.2..v0.8.3) - (2023-12-11)

- [#64](https://github.com/fpagliughi/sockpp/pull/84) Added support for Catch2 v3.x for unit tests. (v2.x still supported)


## [Version 0.8.2](https://github.com/fpagliughi/sockpp/compare/v0.8.1..v0.8.2) - (2023-12-05)

- [#89](https://github.com/fpagliughi/sockpp/issue/89) Fixed generator expression for older CMake
- [#91](https://github.com/fpagliughi/sockpp/issue/91) Fixed uniform_int_distribution<> in UNIX socket example


## [Version 0.8.1](https://github.com/fpagliughi/sockpp/compare/v0.8.0..v0.8.1) - (2023-01-30)

- Cherry picked most of the non-TLS commits in PR [#17](https://github.com/fpagliughi/sockpp/pull/17)
- Connector timeouts
Expand All @@ -15,9 +28,7 @@ Released: 2023-01-30
- [#56](https://github.com/fpagliughi/sockpp/issue/56) handling unix paths with maximum length (no NUL term)
- Fixed outstanding build warnings on Windows when using MSVC

## [Version 0.8.0](https://github.com/fpagliughi/sockpp/compare/v0.7.1..v0.8.0)

Released: 2023-01-17
## [Version 0.8.0](https://github.com/fpagliughi/sockpp/compare/v0.7.1..v0.8.0) - (2023-01-17)

- [Breaking] Library initializer now uses a static singleton created via `socket_initializer::initialize()` call, which can be called repeatedly with no ill effect. Also added global `socketpp::initialize()` function as shortcut.
- Improvements to CMake to better follow modern standards.
Expand Down
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# ---------------------------------------------------------------------------
# This file is part of the "sockpp" C++ socket library.
#
# Copyright (c) 2017-2018 Frank Pagliughi
# Copyright (c) 2017-2023 Frank Pagliughi
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -42,7 +42,7 @@ cmake_minimum_required(VERSION 3.12)

# --- Project setup ---

project(sockpp VERSION "0.8.1")
project(sockpp VERSION "1.0.0")

# --- Build Options ---

Expand Down
47 changes: 6 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# sockpp

[![Build Status](https://travis-ci.org/fpagliughi/sockpp.svg?branch=master)](https://travis-ci.org/fpagliughi/sockpp)

Simple, modern, C++ socket library.

This is a fairly low-level C++ wrapper around the Berkeley sockets library using `socket`, `acceptor,` and `connector` classes that are familiar concepts from other languages.
Expand All @@ -16,54 +14,21 @@ All code in the library lives within the `sockpp` C++ namespace.

## Latest News

The library is reaching a stable API, and is on track for a 1.0 release in the near future. Until then, there may be a few more breaking changes, but hopefully those will be fewer than we have seen so far.

On that note, despite being recently refactored and re-versioned at 0.x, earlier implementations of this library have been in use on production systems since ~2003, particularly with remote embedded Linux data loggers. Things that we now call IoT gateways and edge devices. It can be counted on to be reliable, and if not, please report an issue!

To keep up with the latest announcements for this project, follow me at:

**Twitter:** [@fmpagliughi](https://twitter.com/fmpagliughi)

If you're using this library, tweet at me or send me a message, and let me know how you're using it. I'm always curious to see where it winds up!

## New in v0.8.1
**Mastodon/Fosstodon:** [@[email protected]](https://fosstodon.org/@fpagliughi)

This release attempts to fix some of the outstanding build issues on Windows with MSVC and resolve some old issues and PR commits.

- Cherry picked most of the non-TLS commits in PR [#17](https://github.com/fpagliughi/sockpp/pull/17)
- Connector timeouts
- Stateless reads & writes for streaming sockets w/ functions returning `ioresult`
- Some small bug fixes
- No shutdown on invalid sockets
- [#38](https://github.com/fpagliughi/sockpp/issues/38) Made system libs public for static builds to fix Windows
- [#73](https://github.com/fpagliughi/sockpp/issue/73) Clone a datagram (UDP) socket
- [#74](https://github.com/fpagliughi/sockpp/issue/74) Added `<sys/time.h>` to properly get `timeval` in *nix builds.
- [#56](https://github.com/fpagliughi/sockpp/issue/56) handling unix paths with maximum length (no NUL term)
- Fixed outstanding build warnings on Windows when using MSVC


## New in v0.8.0

This was primarily a release of code that had been sitting in the develop branch for nearly a year. That code mostly improved CMake functionality for downstream projects.
**Twitter:** [@fmpagliughi](https://twitter.com/fmpagliughi)

- [Breaking] Library initializer now uses a static singleton created via `socket_initializer::initialize()` call, which can be called repeatedly with no ill effect. Also added global `socketpp::initialize()` function as shortcut.
- Improvements to CMake to better follow modern standards.
- CMake required version bumped up to 3.12
- Generating CMake files for downstream projects (config, target, version)
- Windows builds default to shared DLL, not static library
- Lots of cleanup
If you're using this library, send me a message, and let me know how you're using it. I'm always curious to see where it winds up!


## Contributing

Contributions are accepted and appreciated. New and unstable work is done in the `develop` branch Please submit all pull requests against that branch, not _master_.
Contributions are accepted and appreciated. New and unstable work is done in the `develop` branch. Please submit all pull requests against that branch, not _master_.

For more information, refer to: [CONTRIBUTING.md](https://github.com/fpagliughi/sockpp/blob/master/CONTRIBUTING.md)

## TODO

- **Secure Sockets** - It would be extremely handy to have support for SSL/TLS built right into the library as an optional feature.
- **SCTP** - The _SCTP_ protocol never caught on, but it seems intriguing, and might be nice to have in the library for experimentation, if not for some internal applications.

## Building the Library

Expand All @@ -76,7 +41,7 @@ CMake is the supported build system.
- _Visual Studio 2015_, or later on WIndows.
- _CMake_ v3.12 or newer.
- _Doxygen_ (optional) to generate API docs.
- _Catch2_ (optional) to build and run unit tests.
- _Catch2_ (optional) v2.x or v3.x to build and run unit tests.

To build with default options:

Expand All @@ -102,7 +67,7 @@ SOCKPP_BUILD_SHARED | ON | Whether to build the shared library
SOCKPP_BUILD_STATIC | OFF | Whether to build the static library
SOCKPP_BUILD_DOCUMENTATION | OFF | Create and install the HTML based API documentation (requires _Doxygen)_
SOCKPP_BUILD_EXAMPLES | OFF | Build example programs
SOCKPP_BUILD_TESTS | OFF | Build the unit tests (requires _Catch2_)
SOCKPP_BUILD_TESTS | OFF | Build the unit tests (requires _Catch2_, v2.x or 3.x)
SOCKPP_BUILD_CAN | OFF | Build SocketCAN support. (Linux only)

Set these using the '-D' switch in the CMake configuration command. For example, to build documentation and example apps:
Expand Down
2 changes: 1 addition & 1 deletion examples/tcp/tcpechotest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ int main(int argc, char* argv[])

random_device rd;
mt19937 reng(rd());
uniform_int_distribution<int> dist(0, 25);
uniform_int_distribution<> dist(0, 25);

for (size_t i=0; i<sz; ++i)
s.push_back('a' + static_cast<char>(dist(reng)));
Expand Down
4 changes: 2 additions & 2 deletions examples/unix/unechotest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ int main(int argc, char* argv[])

random_device rd;
mt19937 reng(rd());
uniform_int_distribution<char> dist(0, 25);
uniform_int_distribution<> dist(0, 25);

for (size_t i=0; i<sz; ++i)
s.push_back('a' + dist(reng));
s.push_back('a' + static_cast<char>(dist(reng)));

auto t_start_tx = high_resolution_clock::now();

Expand Down
2 changes: 1 addition & 1 deletion include/sockpp/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ class socket
*/
template <typename T>
bool set_option(int level, int optname, const T& val) {
return set_option(level, optname, (void*) &val, sizeof(T));
return set_option(level, optname, static_cast<const void*>(&val), sizeof(T));
}
/**
* Places the socket into or out of non-blocking mode.
Expand Down
2 changes: 1 addition & 1 deletion include/sockpp/tcp_acceptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ using tcp_acceptor = acceptor_tmpl<tcp_socket>;

/////////////////////////////////////////////////////////////////////////////
// end namespace sockpp
};
}

#endif // __sockpp_tcp_acceptor_h

2 changes: 1 addition & 1 deletion include/sockpp/tcp_connector.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,6 @@ using tcp_connector = connector_tmpl<tcp_socket>;

/////////////////////////////////////////////////////////////////////////////
// end namespace sockpp
};
}

#endif // __sockpp_tcp_connector_h
3 changes: 1 addition & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,9 @@ target_include_directories(sockpp-objs

# --- Warnings ---

# Maybe set '-Werror' for Release builds?
target_compile_options(sockpp-objs PRIVATE
$<$<CXX_COMPILER_ID:MSVC>:/W3>
$<$<CXX_COMPILER_ID:Clang>:-Wall -Wextra -Wpedantic -Wdocumentation>
$<$<NOT:$<CXX_COMPILER_ID:MSVC,Clang>>:-Wall -Wextra -Wpedantic>
$<$<NOT:$<OR:$<CXX_COMPILER_ID:MSVC>,$<CXX_COMPILER_ID:Clang>>>:-Wall -Wextra -Wpedantic>
)

3 changes: 1 addition & 2 deletions src/exception.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ sys_error::sys_error(int err) : runtime_error(error_str(err)), errno_(err)
// --------------------------------------------------------------------------
// Get a string description of the specified system error.

std::string sys_error::error_str(int err)
string sys_error::error_str(int err)
{
char buf[1024];
buf[0] = '\x0';
Expand Down Expand Up @@ -90,7 +90,6 @@ getaddrinfo_error::getaddrinfo_error(int err, const string& hostname)
{
}


/////////////////////////////////////////////////////////////////////////////
// end namespace 'sockpp'
}
Expand Down
4 changes: 2 additions & 2 deletions src/inet6_address.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ void inet6_address::create(const string& saddr, in_port_t port)
string inet6_address::to_string() const
{
char buf[INET6_ADDRSTRLEN];
auto str = inet_ntop(AF_INET6, (void*) &(addr_.sin6_addr),
auto str = inet_ntop(AF_INET6, static_cast<const void*>(&addr_.sin6_addr),
buf, INET6_ADDRSTRLEN);
return std::string("[") + std::string(str ? str : "<unknown>")
+ "]:" + std::to_string(unsigned(port()));
Expand All @@ -125,7 +125,7 @@ string inet6_address::to_string() const
ostream& operator<<(ostream& os, const inet6_address& addr)
{
char buf[INET6_ADDRSTRLEN];
auto str = inet_ntop(AF_INET6, (void*) &(addr.sockaddr_in6_ptr()->sin6_addr),
auto str = inet_ntop(AF_INET6, static_cast<const void*>(&addr.sockaddr_in6_ptr()->sin6_addr),
buf, INET6_ADDRSTRLEN);
os << "[" << (str ? str : "<unknown>") << "]:" << unsigned(addr.port());
return os;
Expand Down
4 changes: 2 additions & 2 deletions src/inet_address.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ void inet_address::create(const std::string& saddr, in_port_t port)
string inet_address::to_string() const
{
char buf[INET_ADDRSTRLEN];
auto str = inet_ntop(AF_INET, (void*) &(addr_.sin_addr), buf, INET_ADDRSTRLEN);
auto str = inet_ntop(AF_INET, static_cast<const void*>(&addr_.sin_addr), buf, INET_ADDRSTRLEN);
return std::string(str ? str : "<unknown>")
+ ":" + std::to_string(unsigned(port()));
}
Expand All @@ -120,7 +120,7 @@ string inet_address::to_string() const
ostream& operator<<(ostream& os, const inet_address& addr)
{
char buf[INET_ADDRSTRLEN];
auto str = inet_ntop(AF_INET, (void*) &(addr.sockaddr_in_ptr()->sin_addr),
auto str = inet_ntop(AF_INET, static_cast<const void*>(&addr.sockaddr_in_ptr()->sin_addr),
buf, INET_ADDRSTRLEN);
os << (str ? str : "<unknown>") << ":" << unsigned(addr.port());
return os;
Expand Down
3 changes: 2 additions & 1 deletion src/unix/unix_address.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ constexpr size_t unix_address::MAX_PATH_NAME;
unix_address::unix_address(const string& path)
{
addr_.sun_family = ADDRESS_FAMILY;
::strncpy(addr_.sun_path, path.c_str(), MAX_PATH_NAME);
::strncpy(addr_.sun_path, path.c_str(), MAX_PATH_NAME - 1);
addr_.sun_path[MAX_PATH_NAME - 1] = '\0'; // Always ensure null-termination
}

unix_address::unix_address(const sockaddr& addr) : addr_{}
Expand Down
8 changes: 8 additions & 0 deletions tests/unit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@
set(UNIT_TEST_DIR ${PROJECT_SOURCE_DIR})
find_package(Catch2 REQUIRED)

message(STATUS "Catch2 v${Catch2_VERSION}")
if (Catch2_VERSION VERSION_LESS "3.0")
add_definitions(-DCATCH2_V2)
# Put this in if/when deprecating v2.
#message(DEPRECATION "Catch2 version 2.x is deprecated")
endif()

# --- For apps that use threads ---

set(THREADS_PREFER_PTHREAD_FLAG ON)
Expand Down Expand Up @@ -71,6 +78,7 @@ target_include_directories(unit_tests
${SOCKPP_INCLUDE_DIR}
PRIVATE
${SOCKPP_GENERATED_DIR}/include
${CMAKE_CURRENT_SOURCE_DIR}
)

set_target_properties(unit_tests PROPERTIES
Expand Down
48 changes: 48 additions & 0 deletions tests/unit/catch2_version.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// catch2_version.cpp
//
// Unit tests for the `acceptor` class(es).
//
// --------------------------------------------------------------------------
// This file is part of the "sockpp" C++ socket library.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// 1. Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// 3. Neither the name of the copyright holder nor the names of its
// contributors may be used to endorse or promote products derived from this
// software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// --------------------------------------------------------------------------
//

#ifndef __catch2_version_h
#define __catch2_version_h

#ifdef CATCH2_V2
// For Catch2 v2.x
#include "catch2/catch.hpp"
#else
// For Catch2 v3.x
#include "catch2/catch_all.hpp"
#endif

#endif // __catch2_version_h
2 changes: 1 addition & 1 deletion tests/unit/test_acceptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

#include "sockpp/acceptor.h"
#include "sockpp/inet_address.h"
#include "catch2/catch.hpp"
#include "catch2_version.h"
#include <string>

using namespace sockpp;
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/test_connector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

#include "sockpp/connector.h"
#include "sockpp/sock_address.h"
#include "catch2/catch.hpp"
#include "catch2_version.h"
#include <string>

using namespace sockpp;
Expand All @@ -57,7 +57,7 @@ TEST_CASE("connector unspecified address", "[connector]") {

// Windows returns a different error code than *nix
#if defined(_WIN32)
REQUIRE(conn.last_error() == WSAENOTSOCK);
REQUIRE(conn.last_error() == WSAEINVAL);
#else
REQUIRE(conn.last_error() == EAFNOSUPPORT);
#endif
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_datagram_socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

#include "sockpp/datagram_socket.h"
#include "sockpp/inet_address.h"
#include "catch2/catch.hpp"
#include "catch2_version.h"
#include <string>

using namespace sockpp;
Expand Down
Loading