mirror of
https://github.com/ZmnSCPxj/clboss.git
synced 2026-08-13 12:33:20 +02:00
Add clang build configuration to catch C++20 compatibility issues early. Changes: - Add build-clang job to .github/workflows/build.yml - Add missing #include<cstdint> for std::uint* types (clang strict mode) - Add -lexecinfo for FreeBSD in configure.ac (backtrace_symbols) - Fix pessimizing-move warning in test_earningsrebalancer.cpp - Fix CHANGELOG.md formatting 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
50 lines
1.3 KiB
C++
50 lines
1.3 KiB
C++
#ifndef NET_SOCKETFD_HPP
|
|
#define NET_SOCKETFD_HPP
|
|
|
|
#include<cstddef>
|
|
#include<cstdint>
|
|
#include<utility>
|
|
#include<vector>
|
|
#include"Net/Fd.hpp"
|
|
#include"Util/Compiler.hpp"
|
|
|
|
namespace Net {
|
|
|
|
/* RAII class for a network socket file descriptor.
|
|
* See: http://ia800504.us.archive.org/3/items/TheUltimateSo_lingerPageOrWhyIsMyTcpNotReliable/the-ultimate-so_linger-page-or-why-is-my-tcp-not-reliable.html
|
|
* This is most appropriate for sockets that represent a connection
|
|
* between us and a remote computer, not appropriate for sockets
|
|
* that are bound for listening, or which we are still setting up
|
|
* for binding.
|
|
*/
|
|
class SocketFd {
|
|
private:
|
|
Fd fd;
|
|
|
|
public:
|
|
SocketFd(std::nullptr_t _ = nullptr) : fd() { }
|
|
SocketFd(SocketFd&&) =default;
|
|
SocketFd& operator=(SocketFd&&) =default;
|
|
|
|
/* Promote from a plain fd (pre-connecting) to a
|
|
* connected socket.
|
|
*/
|
|
explicit SocketFd(Fd&& o) : fd(std::move(o)) { }
|
|
|
|
~SocketFd();
|
|
|
|
int get() const { return fd.get(); }
|
|
int release() { return fd.release(); }
|
|
void swap(SocketFd& o) { fd.swap(o.fd); }
|
|
void reset(int fd_ = -1) { fd.reset(fd_); }
|
|
|
|
operator bool() const { return (bool)fd; }
|
|
bool operator!() const {return !((bool)fd); }
|
|
|
|
void write(std::vector<std::uint8_t> const&);
|
|
std::vector<std::uint8_t> read(std::size_t);
|
|
};
|
|
|
|
}
|
|
|
|
#endif /* NET_SOCKETFD_HPP */
|