client: add NOLINT comments for array usage and buffer handling
server: mark handleRequest as const and add NOLINT for array index
This commit is contained in:
parent
ce815d18c6
commit
792cda4b52
@ -13,7 +13,7 @@ Client::~Client()
|
|||||||
server.removeFromEpoll(*client_socket_);
|
server.removeFromEpoll(*client_socket_);
|
||||||
};
|
};
|
||||||
|
|
||||||
int Client::parseHeaderforContentLength(const std::string &request)
|
int Client::parseHeaderforContentLength(const std::string &request) //NOLINT
|
||||||
{
|
{
|
||||||
std::string header = "Content-Length: ";
|
std::string header = "Content-Length: ";
|
||||||
size_t pos = request.find(header);
|
size_t pos = request.find(header);
|
||||||
@ -33,8 +33,9 @@ int Client::parseHeaderforContentLength(const std::string &request)
|
|||||||
|
|
||||||
void Client::request()
|
void Client::request()
|
||||||
{
|
{
|
||||||
char buffer[9] = {};
|
char buffer[9] = {}; // NOLINT(cppcoreguidelines-avoid-c-arrays)
|
||||||
ssize_t bytesRead = client_socket_->recv(buffer, sizeof(buffer) - 1);
|
ssize_t bytesRead =
|
||||||
|
client_socket_->recv(buffer, sizeof(buffer) - 1); // NOLINT(cppcoreguidelines-pro-bounds-array-to-pointer-decay)
|
||||||
if (bytesRead < 0)
|
if (bytesRead < 0)
|
||||||
{
|
{
|
||||||
perror("Read error");
|
perror("Read error");
|
||||||
@ -46,8 +47,8 @@ void Client::request()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer[bytesRead] = '\0'; // Null-terminate the buffer
|
buffer[bytesRead] = '\0'; // NOLINT(cppcoreguidelines-pro-bounds-constant-array-index)
|
||||||
requestBuffer_ += buffer;
|
requestBuffer_ += buffer; // NOLINT(cppcoreguidelines-pro-bounds-array-to-pointer-decay)
|
||||||
if (header_.empty())
|
if (header_.empty())
|
||||||
{
|
{
|
||||||
auto headerEnd = requestBuffer_.find("\r\n\r\n");
|
auto headerEnd = requestBuffer_.find("\r\n\r\n");
|
||||||
|
|||||||
@ -138,7 +138,7 @@ const ServerConfig &Server::getConfig(int fd) const
|
|||||||
throw std::runtime_error("Config not found for fd: " + std::to_string(fd));
|
throw std::runtime_error("Config not found for fd: " + std::to_string(fd));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server::handleRequest(struct epoll_event *event)
|
void Server::handleRequest(struct epoll_event *event) const
|
||||||
{
|
{
|
||||||
int client_fd = event->data.fd;
|
int client_fd = event->data.fd;
|
||||||
|
|
||||||
@ -172,7 +172,7 @@ void Server::eventLoop()
|
|||||||
}
|
}
|
||||||
for (int i = 0; i < nfds; ++i)
|
for (int i = 0; i < nfds; ++i)
|
||||||
{
|
{
|
||||||
epoll_event &event = events[i];
|
epoll_event &event = events[i]; // NOLINT(cppcoreguidelines-pro-bounds-constant-array-index)
|
||||||
if ((event.events & EPOLLERR) > 0 || (event.events & EPOLLHUP) > 0)
|
if ((event.events & EPOLLERR) > 0 || (event.events & EPOLLHUP) > 0)
|
||||||
{
|
{
|
||||||
std::cerr << "Epoll error on fd " << event.data.fd << '\n';
|
std::cerr << "Epoll error on fd " << event.data.fd << '\n';
|
||||||
|
|||||||
@ -31,7 +31,7 @@ class Server
|
|||||||
void removeFromEpoll(const Socket &socket) const ;
|
void removeFromEpoll(const Socket &socket) const ;
|
||||||
void setupServerSocket(const ServerConfig &config);
|
void setupServerSocket(const ServerConfig &config);
|
||||||
void handleConnection(struct epoll_event *event);
|
void handleConnection(struct epoll_event *event);
|
||||||
void handleRequest(struct epoll_event *event);
|
void handleRequest(struct epoll_event *event) const;
|
||||||
void responseReady(int client_fd) const;
|
void responseReady(int client_fd) const;
|
||||||
void eventLoop();
|
void eventLoop();
|
||||||
Socket &getListener(int fd) const;
|
Socket &getListener(int fd) const;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user