Use include <cstring> and std::memcpy etc
This commit is contained in:
@@ -1,10 +1,9 @@
|
||||
#include "connection.hpp"
|
||||
|
||||
#include <cerrno>
|
||||
#include <climits>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
|
||||
#include "server.hpp" // Need this for releaseBackToServer implementation
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ ConnectionRegistry::~ConnectionRegistry() {
|
||||
|
||||
void ConnectionRegistry::store(int fd, std::unique_ptr<Connection> connection) {
|
||||
if (fd < 0 || static_cast<size_t>(fd) >= max_fds_) {
|
||||
abort();
|
||||
std::abort();
|
||||
}
|
||||
// Release ownership from unique_ptr and store raw pointer
|
||||
connections_[fd].store(connection.release(), std::memory_order_release);
|
||||
@@ -55,7 +55,7 @@ void ConnectionRegistry::store(int fd, std::unique_ptr<Connection> connection) {
|
||||
|
||||
std::unique_ptr<Connection> ConnectionRegistry::remove(int fd) {
|
||||
if (fd < 0 || static_cast<size_t>(fd) >= max_fds_) {
|
||||
abort();
|
||||
std::abort();
|
||||
}
|
||||
return std::unique_ptr<Connection>(
|
||||
connections_[fd].exchange(nullptr, std::memory_order_acquire));
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
%{
|
||||
#include <string.h>
|
||||
#include <cstring>
|
||||
%}
|
||||
%define hash-function-name hash_json_token
|
||||
%define lookup-function-name lookup_json_token
|
||||
|
||||
17
src/main.cpp
17
src/main.cpp
@@ -6,6 +6,7 @@
|
||||
#include "server.hpp"
|
||||
#include <atomic>
|
||||
#include <csignal>
|
||||
#include <cstring>
|
||||
#include <fcntl.h>
|
||||
#include <iostream>
|
||||
#include <netdb.h>
|
||||
@@ -44,7 +45,7 @@ std::vector<int> create_listen_sockets(const weaseldb::Config &config) {
|
||||
unlink(config.server.unix_socket_path.c_str());
|
||||
|
||||
struct sockaddr_un addr;
|
||||
memset(&addr, 0, sizeof(addr));
|
||||
std::memset(&addr, 0, sizeof(addr));
|
||||
addr.sun_family = AF_UNIX;
|
||||
|
||||
if (config.server.unix_socket_path.length() >= sizeof(addr.sun_path)) {
|
||||
@@ -52,8 +53,8 @@ std::vector<int> create_listen_sockets(const weaseldb::Config &config) {
|
||||
std::abort();
|
||||
}
|
||||
|
||||
strncpy(addr.sun_path, config.server.unix_socket_path.c_str(),
|
||||
sizeof(addr.sun_path) - 1);
|
||||
std::strncpy(addr.sun_path, config.server.unix_socket_path.c_str(),
|
||||
sizeof(addr.sun_path) - 1);
|
||||
|
||||
if (bind(sfd, (struct sockaddr *)&addr, sizeof(addr)) == -1) {
|
||||
perror("bind");
|
||||
@@ -74,7 +75,7 @@ std::vector<int> create_listen_sockets(const weaseldb::Config &config) {
|
||||
struct addrinfo *result, *rp;
|
||||
int s;
|
||||
|
||||
memset(&hints, 0, sizeof(hints));
|
||||
std::memset(&hints, 0, sizeof(hints));
|
||||
hints.ai_family = AF_UNSPEC; /* Allow IPv4 or IPv6 */
|
||||
hints.ai_socktype = SOCK_STREAM; /* stream socket */
|
||||
hints.ai_flags = AI_PASSIVE; /* For wildcard IP address */
|
||||
@@ -86,7 +87,7 @@ std::vector<int> create_listen_sockets(const weaseldb::Config &config) {
|
||||
s = getaddrinfo(config.server.bind_address.c_str(),
|
||||
std::to_string(config.server.port).c_str(), &hints, &result);
|
||||
if (s != 0) {
|
||||
fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(s));
|
||||
std::fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(s));
|
||||
std::abort();
|
||||
}
|
||||
|
||||
@@ -254,9 +255,9 @@ int main(int argc, char *argv[]) {
|
||||
g_server = server.get();
|
||||
|
||||
// Setup signal handling
|
||||
signal(SIGPIPE, SIG_IGN);
|
||||
signal(SIGTERM, signal_handler);
|
||||
signal(SIGINT, signal_handler);
|
||||
std::signal(SIGPIPE, SIG_IGN);
|
||||
std::signal(SIGTERM, signal_handler);
|
||||
std::signal(SIGINT, signal_handler);
|
||||
|
||||
std::cout << "Starting WeaselDB HTTP server..." << std::endl;
|
||||
server->run();
|
||||
|
||||
@@ -131,7 +131,7 @@ void Server::shutdown() {
|
||||
// Write single byte to avoid partial write complexity
|
||||
while (write(shutdown_pipe_[1], &val, 1) == -1) {
|
||||
if (errno != EINTR) {
|
||||
abort(); // graceful shutdown didn't work. Let's go ungraceful.
|
||||
std::abort(); // graceful shutdown didn't work. Let's go ungraceful.
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -328,7 +328,7 @@ void Server::start_io_threads(std::vector<std::thread> &threads) {
|
||||
continue;
|
||||
}
|
||||
perror("epoll_wait");
|
||||
abort();
|
||||
std::abort();
|
||||
}
|
||||
|
||||
ready_listen_fds.clear(); // Clear from previous iteration
|
||||
@@ -384,7 +384,7 @@ void Server::start_io_threads(std::vector<std::thread> &threads) {
|
||||
if (errno == EINTR)
|
||||
continue;
|
||||
perror("accept4");
|
||||
abort();
|
||||
std::abort();
|
||||
}
|
||||
|
||||
// Check connection limit
|
||||
|
||||
@@ -344,10 +344,10 @@ public:
|
||||
// Violating preconditions results in program termination via abort().
|
||||
[[nodiscard]] ProducerGuard push(uint32_t const size, bool block) {
|
||||
if (size == 0) {
|
||||
abort();
|
||||
std::abort();
|
||||
}
|
||||
if (size > slot_count) {
|
||||
abort();
|
||||
std::abort();
|
||||
}
|
||||
// Reserve a slot to construct an item, but don't publish to consumer yet
|
||||
uint32_t slot;
|
||||
|
||||
Reference in New Issue
Block a user