Avoid exceptions
This commit is contained in:
@@ -9,7 +9,6 @@
|
||||
#include <netdb.h>
|
||||
#include <netinet/tcp.h>
|
||||
#include <pthread.h>
|
||||
#include <stdexcept>
|
||||
#include <sys/epoll.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/un.h>
|
||||
@@ -39,12 +38,12 @@ Server::Server(const weaseldb::Config &config, ConnectionHandler &handler,
|
||||
for (int fd : listen_fds_) {
|
||||
int flags = fcntl(fd, F_GETFL, 0);
|
||||
if (flags == -1) {
|
||||
perror("fcntl F_GETFL on provided listen fd");
|
||||
throw std::runtime_error("Failed to get flags for provided listen fd");
|
||||
perror("fcntl F_GETFL");
|
||||
std::abort();
|
||||
}
|
||||
if (fcntl(fd, F_SETFL, flags | O_NONBLOCK) == -1) {
|
||||
perror("fcntl F_SETFL O_NONBLOCK on provided listen fd");
|
||||
throw std::runtime_error("Failed to set provided listen fd non-blocking");
|
||||
perror("fcntl F_SETFL O_NONBLOCK");
|
||||
std::abort();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -179,14 +178,14 @@ int Server::createLocalConnection() {
|
||||
|
||||
int flags = fcntl(server_fd, F_GETFL, 0);
|
||||
if (flags == -1) {
|
||||
perror("fcntl F_GETFL on provided listen fd");
|
||||
throw std::runtime_error(
|
||||
"Failed to get flags for server side of local connection");
|
||||
std::fprintf(stderr,
|
||||
"Server::createLocalConnection: fcntl F_GETFL failed\n");
|
||||
std::abort();
|
||||
}
|
||||
if (fcntl(server_fd, F_SETFL, flags | O_NONBLOCK) == -1) {
|
||||
perror("fcntl F_SETFL O_NONBLOCK on provided listen fd");
|
||||
throw std::runtime_error(
|
||||
"Failed to set server side of local connection to non-blocking");
|
||||
std::fprintf(stderr,
|
||||
"Server::createLocalConnection: fcntl F_SETFL failed\n");
|
||||
std::abort();
|
||||
}
|
||||
|
||||
// Create sockaddr_storage for the connection
|
||||
@@ -226,14 +225,14 @@ int Server::createLocalConnection() {
|
||||
void Server::setup_shutdown_pipe() {
|
||||
if (pipe(shutdown_pipe_) == -1) {
|
||||
perror("pipe");
|
||||
throw std::runtime_error("Failed to create shutdown pipe");
|
||||
std::abort();
|
||||
}
|
||||
|
||||
// Set both ends to close-on-exec
|
||||
if (fcntl(shutdown_pipe_[0], F_SETFD, FD_CLOEXEC) == -1 ||
|
||||
fcntl(shutdown_pipe_[1], F_SETFD, FD_CLOEXEC) == -1) {
|
||||
perror("fcntl FD_CLOEXEC");
|
||||
throw std::runtime_error("Failed to set close-on-exec for shutdown pipe");
|
||||
std::abort();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -244,8 +243,8 @@ void Server::create_epoll_instances() {
|
||||
for (int i = 0; i < config_.server.epoll_instances; ++i) {
|
||||
epoll_fds_[i] = epoll_create1(EPOLL_CLOEXEC);
|
||||
if (epoll_fds_[i] == -1) {
|
||||
perror("epoll_create");
|
||||
throw std::runtime_error("Failed to create epoll instance");
|
||||
perror("epoll_create1");
|
||||
std::abort();
|
||||
}
|
||||
|
||||
// Add shutdown pipe to each epoll instance
|
||||
@@ -256,7 +255,7 @@ void Server::create_epoll_instances() {
|
||||
if (epoll_ctl(epoll_fds_[i], EPOLL_CTL_ADD, shutdown_pipe_[0],
|
||||
&shutdown_event) == -1) {
|
||||
perror("epoll_ctl shutdown pipe");
|
||||
throw std::runtime_error("Failed to add shutdown pipe to epoll");
|
||||
std::abort();
|
||||
}
|
||||
|
||||
// Add all listen sockets to each epoll instance with EPOLLEXCLUSIVE to
|
||||
@@ -268,7 +267,7 @@ void Server::create_epoll_instances() {
|
||||
if (epoll_ctl(epoll_fds_[i], EPOLL_CTL_ADD, listen_fd, &listen_event) ==
|
||||
-1) {
|
||||
perror("epoll_ctl listen socket");
|
||||
throw std::runtime_error("Failed to add listen socket to epoll");
|
||||
std::abort();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user