Fix type confusion
This commit is contained in:
@@ -43,7 +43,7 @@ void Server::run() {
|
|||||||
// Add shutdown pipe to epoll instance
|
// Add shutdown pipe to epoll instance
|
||||||
struct epoll_event shutdown_event;
|
struct epoll_event shutdown_event;
|
||||||
shutdown_event.events = EPOLLIN;
|
shutdown_event.events = EPOLLIN;
|
||||||
shutdown_event.data.fd = shutdown_pipe_[0];
|
shutdown_event.data.ptr = const_cast<char *>(&shutdown_pipe_tag);
|
||||||
|
|
||||||
if (epoll_ctl(epollfd_, EPOLL_CTL_ADD, shutdown_pipe_[0], &shutdown_event) ==
|
if (epoll_ctl(epollfd_, EPOLL_CTL_ADD, shutdown_pipe_[0], &shutdown_event) ==
|
||||||
-1) {
|
-1) {
|
||||||
@@ -54,7 +54,7 @@ void Server::run() {
|
|||||||
// Add listen socket to epoll with EPOLLEXCLUSIVE to prevent thundering herd
|
// Add listen socket to epoll with EPOLLEXCLUSIVE to prevent thundering herd
|
||||||
struct epoll_event listen_event;
|
struct epoll_event listen_event;
|
||||||
listen_event.events = EPOLLIN | EPOLLEXCLUSIVE;
|
listen_event.events = EPOLLIN | EPOLLEXCLUSIVE;
|
||||||
listen_event.data.fd = listen_sockfd_;
|
listen_event.data.ptr = const_cast<char *>(&listen_socket_tag);
|
||||||
if (epoll_ctl(epollfd_, EPOLL_CTL_ADD, listen_sockfd_, &listen_event) == -1) {
|
if (epoll_ctl(epollfd_, EPOLL_CTL_ADD, listen_sockfd_, &listen_event) == -1) {
|
||||||
perror("epoll_ctl listen socket");
|
perror("epoll_ctl listen socket");
|
||||||
throw std::runtime_error("Failed to add listen socket to epoll");
|
throw std::runtime_error("Failed to add listen socket to epoll");
|
||||||
@@ -290,13 +290,11 @@ void Server::start_io_threads() {
|
|||||||
int batch_count = 0;
|
int batch_count = 0;
|
||||||
for (int i = 0; i < event_count; ++i) {
|
for (int i = 0; i < event_count; ++i) {
|
||||||
// Check for shutdown event
|
// Check for shutdown event
|
||||||
// TODO type confusion in data union
|
if (events[i].data.ptr == &shutdown_pipe_tag) {
|
||||||
if (events[i].data.fd == shutdown_pipe_[0]) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Check for new connections
|
// Check for new connections
|
||||||
// TODO type confusion in data union
|
if (events[i].data.ptr == &listen_socket_tag) {
|
||||||
if (events[i].data.fd == listen_sockfd_) {
|
|
||||||
listenReady = true;
|
listenReady = true;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -110,6 +110,10 @@ private:
|
|||||||
int epollfd_ = -1;
|
int epollfd_ = -1;
|
||||||
int listen_sockfd_ = -1;
|
int listen_sockfd_ = -1;
|
||||||
|
|
||||||
|
// Unique tags for special events to avoid type confusion in epoll data union
|
||||||
|
static inline const char listen_socket_tag = 0;
|
||||||
|
static inline const char shutdown_pipe_tag = 0;
|
||||||
|
|
||||||
// Private helper methods
|
// Private helper methods
|
||||||
void setup_shutdown_pipe();
|
void setup_shutdown_pipe();
|
||||||
void setup_signal_handling();
|
void setup_signal_handling();
|
||||||
|
|||||||
Reference in New Issue
Block a user