Skip to content

Commit

Permalink
dont resize the ke_list
Browse files Browse the repository at this point in the history
  • Loading branch information
braindigitalis committed Nov 19, 2024
1 parent a2a21c9 commit 6a36514
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions src/dpp/socketengines/kqueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <dpp/exception.h>
#include <memory>
#include <vector>
#include <array>
#include <sys/types.h>
#include <unistd.h>
#include <dpp/cluster.h>
Expand All @@ -33,15 +34,14 @@ namespace dpp {
struct socket_engine_kqueue : public socket_engine_base {

int kqueue_handle{INVALID_SOCKET};
std::vector<struct kevent> ke_list;
std::array<struct kevent, 65536> ke_list;

socket_engine_kqueue(const socket_engine_kqueue&) = delete;
socket_engine_kqueue(socket_engine_kqueue&&) = delete;
socket_engine_kqueue& operator=(const socket_engine_kqueue&) = delete;
socket_engine_kqueue& operator=(socket_engine_kqueue&&) = delete;

explicit socket_engine_kqueue(cluster* creator) : socket_engine_base(creator), kqueue_handle(kqueue()) {
ke_list.resize(16);
if (kqueue_handle == -1) {
throw dpp::connection_exception("Failed to initialise kqueue()");
}
Expand All @@ -57,7 +57,7 @@ struct socket_engine_kqueue : public socket_engine_base {
struct timespec ts{};
ts.tv_sec = 1;

int i = kevent(kqueue_handle, NULL, 0, &ke_list.front(), static_cast<int>(ke_list.size()), &ts);
int i = kevent(kqueue_handle, NULL, 0, ke_list.data(), static_cast<int>(ke_list.size()), &ts);
if (i < 0) {
return;
}
Expand Down Expand Up @@ -111,9 +111,6 @@ struct socket_engine_kqueue : public socket_engine_base {
EV_SET(&ke, e.fd, EVFILT_WRITE, EV_ADD | EV_ONESHOT, 0, 0, static_cast<CAST_TYPE>(se));
kevent(kqueue_handle, &ke, 1, 0, 0, nullptr);
}
if (fds.size() * 3 > ke_list.size()) {
ke_list.resize(fds.size() * 3);
}
}
return r;
}
Expand All @@ -131,9 +128,6 @@ struct socket_engine_kqueue : public socket_engine_base {
EV_SET(&ke, e.fd, EVFILT_WRITE, EV_ADD | EV_ONESHOT, 0, 0, static_cast<CAST_TYPE>(se));
kevent(kqueue_handle, &ke, 1, 0, 0, nullptr);
}
if (fds.size() * 3 > ke_list.size()) {
ke_list.resize(fds.size() * 3);
}
}
return r;
}
Expand Down

0 comments on commit 6a36514

Please sign in to comment.