mirror of
https://github.com/fpagliughi/sockpp.git
synced 2026-01-12 00:04:45 +08:00
Ran a spellcheck and fixed typos
This commit is contained in:
@@ -99,15 +99,15 @@ Released: 2022-01-24
|
||||
The work in this branch is proceeding to add support for IPv6 and refactor the class hierarchies to better support the different address families without so much redundant code.
|
||||
|
||||
- IPv6 support: `inet6_address`, `tcp6_acceptor`, `tcp_connector`, etc.
|
||||
- (Breaking change) The `sock_address` class is now contains storage for any type of address and follows copy semantics. Previously it was a non-owning reference class. That reference class now exists as `sock_addresss_ref`.
|
||||
- Generic base classses are being re-implemented to use _sock_address_ and _sock_address_ref_ as generic addresses.
|
||||
- (Breaking change) The `sock_address` class is now contains storage for any type of address and follows copy semantics. Previously it was a non-owning reference class. That reference class now exists as `sock_address_ref`.
|
||||
- Generic base classes are being re-implemented to use _sock_address_ and _sock_address_ref_ as generic addresses.
|
||||
- (Breaking change) In the `socket` class(es) the `bool address(address&)` and `bool peer_address(addr&)` forms of getting the socket addresses have been removed in favor of the ones that simply return the address.
|
||||
Added `get_option()` and `set_option()` methods to the base `socket`class.
|
||||
- The GNU Make build system (Makefile) was deprecated and removed.
|
||||
|
||||
## Version 0.3
|
||||
|
||||
- Socket class hierarcy now splits out for streaming and datagram sockets.
|
||||
- Socket class hierarchy now splits out for streaming and datagram sockets.
|
||||
- Support for UNIX-domain sockets.
|
||||
- New modern CMake build system.
|
||||
- GNU Make system marked for deprecation.
|
||||
|
||||
11
README.md
11
README.md
@@ -20,7 +20,7 @@ All code in the library lives within the `sockpp` C++ namespace.
|
||||
|
||||
## Latest News
|
||||
|
||||
Version 1.0 is releaed!
|
||||
Version 1.0 is released!
|
||||
|
||||
As breaking changes were starting to accumulate in the current development branch, the decision was made to release the API that has been fairly stable for the last few years as 1.0. This is from the latest v0.8.x line. That will make things going forward less confusing and allow us to maintain the v1.x branch.
|
||||
|
||||
@@ -108,6 +108,7 @@ 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_WITH_UNIX_SOCKETS | ON (*nix), OFF (Win) | Include support for UNIX-domain sockets
|
||||
SOCKPP_WITH_CAN | OFF | Include SocketCAN support. (Linux only)
|
||||
|
||||
Set these using the '-D' switch in the CMake configuration command. For example, to build documentation and example apps:
|
||||
@@ -153,7 +154,7 @@ Note that the options in the config file should already be present in the file b
|
||||
|
||||
#### OpenSSL
|
||||
|
||||
The `sockpp` OpenSSL wrapper is currenly being built and tested with OpenSSL v3.0
|
||||
The `sockpp` OpenSSL wrapper is currently being built and tested with OpenSSL v3.0
|
||||
|
||||
## TCP Sockets
|
||||
|
||||
@@ -256,11 +257,11 @@ Examples are in the [examples/unix](https://github.com/fpagliughi/sockpp/tree/ma
|
||||
|
||||
### SocketCAN (CAN bus on Linux)
|
||||
|
||||
The Controller Area Network (CAN bus) is a relatively simple protocol typically used by microcontrollers to communicate inside an automobile or industrial machine. Linux has the _SocketCAN_ package which allows processes to share acces to a physical CAN bus interface using sockets in user space. See: [Linux SocketCAN](https://www.kernel.org/doc/html/latest/networking/can.html)
|
||||
The Controller Area Network (CAN bus) is a relatively simple protocol typically used by microcontrollers to communicate inside an automobile or industrial machine. Linux has the _SocketCAN_ package which allows processes to share access to a physical CAN bus interface using sockets in user space. See: [Linux SocketCAN](https://www.kernel.org/doc/html/latest/networking/can.html)
|
||||
|
||||
At the lowest level, CAN devices write individual packets, called "frames" to a specific numeric addresses on the bus.
|
||||
|
||||
For examle a device with a temperature sensor might read the temperature peroidically and write it to the bus as a raw 32-bit integer, like:
|
||||
For example a device with a temperature sensor might read the temperature peirodically and write it to the bus as a raw 32-bit integer, like:
|
||||
|
||||
```
|
||||
can_address addr("CAN0");
|
||||
@@ -324,7 +325,7 @@ In this case, _handle_connection_ would be a function that takes a socket by val
|
||||
|
||||
Since a `socket` can not be copied, the only choice would be to move the socket to a function like this.
|
||||
|
||||
It is a common patern, especially in client applications, to have one thread to read from a socket and another thread to write to the socket. In this case the underlying socket handle can be considered thread safe (one read thread and one write thread). But even in this scenario, a `sockpp::socket` object is still not thread-safe due especially to the cached error value. The write thread might see an error that happened on the read thread and visa versa.
|
||||
It is a common pattern, especially in client applications, to have one thread to read from a socket and another thread to write to the socket. In this case the underlying socket handle can be considered thread safe (one read thread and one write thread). But even in this scenario, a `sockpp::socket` object is still not thread-safe due especially to the cached error value. The write thread might see an error that happened on the read thread and visa versa.
|
||||
|
||||
The solution for this case is to use the `socket::clone()` method to make a copy of the socket. This will use the system's `dup()` function or similar create another socket with a duplicated copy of the socket handle. This has the added benefit that each copy of the socket can maintain an independent lifetime. The underlying socket will not be closed until both objects go out of scope.
|
||||
|
||||
|
||||
9
_typos.toml
Normal file
9
_typos.toml
Normal file
@@ -0,0 +1,9 @@
|
||||
[default.extend-words]
|
||||
thr = "thr"
|
||||
PNG = "PNG"
|
||||
|
||||
[files]
|
||||
extend-exclude = [
|
||||
"*.fodt"
|
||||
]
|
||||
|
||||
@@ -1948,7 +1948,7 @@ PREDEFINED =
|
||||
EXPAND_AS_DEFINED =
|
||||
|
||||
# If the SKIP_FUNCTION_MACROS tag is set to YES then doxygen's preprocessor will
|
||||
# remove all refrences to function-like macros that are alone on a line, have an
|
||||
# remove all references to function-like macros that are alone on a line, have an
|
||||
# all uppercase name, and do not end with a semicolon. Such function macros are
|
||||
# typically used for boiler-plate code, and will confuse the parser if not
|
||||
# removed.
|
||||
|
||||
@@ -128,7 +128,7 @@ public:
|
||||
*/
|
||||
can_address(const can_address& addr) noexcept : addr_(addr.addr_) {}
|
||||
/**
|
||||
* Attempts to get the address for the secified CAN interface
|
||||
* Attempts to get the address for the specified CAN interface
|
||||
*
|
||||
* @param iface The name of the CAN interface
|
||||
* @return A result with a CAN address, if successful, or an error code
|
||||
|
||||
@@ -205,7 +205,7 @@ public:
|
||||
// ----- I/O -----
|
||||
|
||||
/**
|
||||
* Sends a frame to the CAN interfacce at the specified address.
|
||||
* Sends a frame to the CAN interface at the specified address.
|
||||
* @param frame The CAN frame to send.
|
||||
* @param flags The flags. See send(2).
|
||||
* @param addr The remote destination of the data.
|
||||
|
||||
@@ -168,7 +168,7 @@ public:
|
||||
/**
|
||||
* Creates a failed result from an error code.
|
||||
* @param err The error code from an operation.
|
||||
* @return The result of an unsucessful operation.
|
||||
* @return The result of an unsuccessful operation.
|
||||
*/
|
||||
static result from_error(const error_code& err) { return result{T{}, err}; }
|
||||
/**
|
||||
@@ -182,7 +182,7 @@ public:
|
||||
return result{T{}, {ec, ecat}};
|
||||
}
|
||||
/**
|
||||
* Creates an unsuccesful result from a portable error condition.
|
||||
* Creates an unsuccessful result from a portable error condition.
|
||||
* @param err The error
|
||||
* @return The result of an unsuccessful operation.
|
||||
*/
|
||||
@@ -295,7 +295,7 @@ public:
|
||||
/**
|
||||
* Create a successful result with the specified value.
|
||||
*
|
||||
* @param val The succesful return value from the operation.
|
||||
* @param val The successful return value from the operation.
|
||||
* @return A success result.
|
||||
*/
|
||||
template <typename T>
|
||||
@@ -306,7 +306,7 @@ result<T> success(const T& val) {
|
||||
/**
|
||||
* Create a successful result with the specified value.
|
||||
*
|
||||
* @param val The succesful return value from the operation.
|
||||
* @param val The successful return value from the operation.
|
||||
* @return A success result.
|
||||
*/
|
||||
template <typename T>
|
||||
|
||||
@@ -155,7 +155,7 @@ public:
|
||||
* This is primarily required for Win32, to startup the WinSock DLL.
|
||||
*
|
||||
* On Unix-style platforms it disables SIGPIPE signals. Errors are handled
|
||||
* by functon return values and exceptions.
|
||||
* by function return values and exceptions.
|
||||
*/
|
||||
void initialize();
|
||||
|
||||
@@ -410,8 +410,8 @@ public:
|
||||
* SOL_SOCKET.
|
||||
* @param optname The option passed directly to the protocol module.
|
||||
* @param optval The buffer for the value to retrieve
|
||||
* @param optlen Initially contains the lenth of the buffer, and on return
|
||||
* contains the length of the value retrieved.
|
||||
* @param optlen Initially contains the length of the buffer, and on
|
||||
* return contains the length of the value retrieved.
|
||||
*
|
||||
* @return bool @em true if the value was retrieved, @em false if an error
|
||||
* occurred.
|
||||
@@ -469,7 +469,7 @@ public:
|
||||
* SOL_SOCKET.
|
||||
* @param optname The option passed directly to the protocol module.
|
||||
* @param optval The buffer with the value to set.
|
||||
* @param optlen Contains the lenth of the value buffer.
|
||||
* @param optlen Contains the length of the value buffer.
|
||||
*
|
||||
* @return bool @em true if the value was set, @em false if an error
|
||||
* occurred.
|
||||
@@ -528,7 +528,7 @@ public:
|
||||
/**
|
||||
* Gets the value of the `SO_REUSEADDR` option on the socket.
|
||||
* @return The value of the `SO_REUSEADDR` option on the socket on
|
||||
* success, an error code on faliure.
|
||||
* success, an error code on failure.
|
||||
*/
|
||||
result<bool> reuse_address() const noexcept {
|
||||
return get_option<bool>(SOL_SOCKET, SO_REUSEADDR);
|
||||
@@ -545,7 +545,7 @@ public:
|
||||
/**
|
||||
* Gets the value of the `SO_REUSEPORT` option on the socket.
|
||||
* @return The value of the `SO_REUSEPORT` option on the socket on
|
||||
* success, an error code on faliure.
|
||||
* success, an error code on failure.
|
||||
*/
|
||||
result<bool> reuse_port() const noexcept {
|
||||
return get_option<bool>(SOL_SOCKET, SO_REUSEPORT);
|
||||
|
||||
@@ -185,8 +185,8 @@ public:
|
||||
virtual result<> read_timeout(const microseconds& to);
|
||||
/**
|
||||
* Set a timeout for read operations.
|
||||
* Sets the timout that the device uses for read operations. Not all
|
||||
* devices support timouts, so the caller should prepare for failure.
|
||||
* Sets the timeout that the device uses for read operations. Not all
|
||||
* devices support timeouts, so the caller should prepare for failure.
|
||||
* @param to The amount of time to wait for the operation to complete.
|
||||
* @return @em true on success, @em false on failure.
|
||||
*/
|
||||
@@ -225,16 +225,16 @@ public:
|
||||
virtual result<size_t> write(const std::vector<iovec>& ranges);
|
||||
/**
|
||||
* Set a timeout for write operations.
|
||||
* Sets the timout that the device uses for write operations. Not all
|
||||
* devices support timouts, so the caller should prepare for failure.
|
||||
* Sets the timeout that the device uses for write operations. Not all
|
||||
* devices support timeouts, so the caller should prepare for failure.
|
||||
* @param to The amount of time to wait for the operation to complete.
|
||||
* @return @em true on success, @em false on failure.
|
||||
*/
|
||||
virtual result<> write_timeout(const microseconds& to);
|
||||
/**
|
||||
* Set a timeout for write operations.
|
||||
* Sets the timout that the device uses for write operations. Not all
|
||||
* devices support timouts, so the caller should prepare for failure.
|
||||
* Sets the timeout that the device uses for write operations. Not all
|
||||
* devices support timeouts, so the caller should prepare for failure.
|
||||
* @param to The amount of time to wait for the operation to complete.
|
||||
* @return @em true on success, @em false on failure.
|
||||
*/
|
||||
@@ -300,7 +300,7 @@ public:
|
||||
return *this;
|
||||
}
|
||||
/**
|
||||
* Cretates a stream socket.
|
||||
* Creates a stream socket.
|
||||
* @param protocol The particular protocol to be used with the sockets
|
||||
* @return A stream socket
|
||||
*/
|
||||
|
||||
@@ -182,7 +182,7 @@ public:
|
||||
/**
|
||||
* Set the private key from a file.
|
||||
* @param keyFile The private key file.
|
||||
* @return Error code on faliure.
|
||||
* @return Error code on failure.
|
||||
*/
|
||||
auto key_file(const string& keyFile) -> self& {
|
||||
if (!ec_) {
|
||||
|
||||
@@ -194,7 +194,7 @@ public:
|
||||
/**
|
||||
* Set the private key from a file.
|
||||
* @param keyFile The private key file.
|
||||
* @return Error code on faliure.
|
||||
* @return Error code on failure.
|
||||
*/
|
||||
result<> set_key_file(const string& keyFile);
|
||||
/**
|
||||
|
||||
@@ -146,7 +146,7 @@ void mbedtls_socket::setup_bio(bool nonblocking) {
|
||||
mbedtls_ssl_recv_timeout_t* f_recv_timeout = nullptr;
|
||||
// "The two most common use cases are:
|
||||
// - non-blocking I/O, f_recv != nullptr, f_recv_timeout == nullptr
|
||||
// - blocking I/O, f_recv == nullptr, f_recv_timout != nullptr"
|
||||
// - blocking I/O, f_recv == nullptr, f_recv_timeout != nullptr"
|
||||
if (nonblocking) {
|
||||
f_recv = [](void* ctx, uchar* buf, size_t n) {
|
||||
if (auto res = ((mbedtls_socket*)ctx)->bio_recv(buf, n); res)
|
||||
|
||||
@@ -106,6 +106,6 @@ TEST_CASE("stream_socket address constructor", "[stream_socket]") {
|
||||
// --------------------------------------------------------------------------
|
||||
// Connected tests
|
||||
|
||||
TEST_CASE("stream_socket readn, writen", "[stream_socket]") {
|
||||
TEST_CASE("stream_socket readn, written", "[stream_socket]") {
|
||||
// auto lsock = stream_socket::create(AF
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user