Replace VLA with thread local vectors

This commit is contained in:
2025-08-22 18:04:12 -04:00
parent f51f257df6
commit c58a00a34f
3 changed files with 27 additions and 35 deletions

View File

@@ -1,10 +1,14 @@
#include "connection.hpp"
#include "server.hpp" // Need this for releaseBackToServer implementation
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <errno.h>
#include <limits.h>
// Static thread-local storage for iovec buffer
static thread_local std::vector<struct iovec> g_iovec_buffer{IOV_MAX};
Connection::Connection(struct sockaddr_storage addr, int fd, int64_t id,
size_t epoll_index, ConnectionHandler *handler,
Server &server)
@@ -62,8 +66,9 @@ int Connection::readBytes(char *buf, size_t buffer_size) {
bool Connection::writeBytes() {
while (!messages_.empty()) {
// Build iovec array up to IOV_MAX limit
struct iovec iov[IOV_MAX];
// Build iovec array up to IOV_MAX limit using thread-local vector
assert(g_iovec_buffer.size() == IOV_MAX);
struct iovec *iov = g_iovec_buffer.data();
int iov_count = 0;
for (auto it = messages_.begin();