mirror of
https://github.com/KeyZox71/webserv.git
synced 2025-05-11 07:28:47 +02:00
「🔨」 fix: fixed invalid read and accept issue
This commit is contained in:
@ -6,7 +6,7 @@
|
|||||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/04/11 16:11:40 by adjoly #+# #+# */
|
/* Created: 2025/04/11 16:11:40 by adjoly #+# #+# */
|
||||||
/* Updated: 2025/04/23 15:31:41 by adjoly ### ########.fr */
|
/* Updated: 2025/04/23 16:22:22 by adjoly ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -93,6 +93,7 @@ void Server::_run(void) {
|
|||||||
fd.events = POLLIN;
|
fd.events = POLLIN;
|
||||||
_client_fds.push_back(fd);
|
_client_fds.push_back(fd);
|
||||||
_client_data.push_back(NULL);
|
_client_data.push_back(NULL);
|
||||||
|
_log->debug("new socket in poll");
|
||||||
}
|
}
|
||||||
|
|
||||||
// to add signal instead of 727
|
// to add signal instead of 727
|
||||||
@ -112,6 +113,8 @@ void Server::_run(void) {
|
|||||||
accept((*it), (struct sockaddr *)&client_addr, &addrlen);
|
accept((*it), (struct sockaddr *)&client_addr, &addrlen);
|
||||||
|
|
||||||
if (client_fd < 0) {
|
if (client_fd < 0) {
|
||||||
|
if (errno == EAGAIN || errno == EWOULDBLOCK)
|
||||||
|
continue;
|
||||||
std::stringstream str;
|
std::stringstream str;
|
||||||
str << "Accept failed: ";
|
str << "Accept failed: ";
|
||||||
str << strerror(errno);
|
str << strerror(errno);
|
||||||
@ -122,9 +125,11 @@ void Server::_run(void) {
|
|||||||
pollfd pfd;
|
pollfd pfd;
|
||||||
pfd.fd = client_fd;
|
pfd.fd = client_fd;
|
||||||
pfd.events = POLLIN | POLLOUT;
|
pfd.events = POLLIN | POLLOUT;
|
||||||
|
pfd.revents = 0;
|
||||||
_client_fds.push_back(pfd);
|
_client_fds.push_back(pfd);
|
||||||
struct sockaddr_in* new_client_sock = new sockaddr_in();
|
struct sockaddr_in *new_client_sock = new sockaddr_in();
|
||||||
std::memmove(new_client_sock, &client_addr, sizeof(struct sockaddr_in));
|
std::memmove(new_client_sock, &client_addr,
|
||||||
|
sizeof(struct sockaddr_in));
|
||||||
_client_data.push_back(new_client_sock);
|
_client_data.push_back(new_client_sock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/04/17 11:58:42 by adjoly #+# #+# */
|
/* Created: 2025/04/17 11:58:42 by adjoly #+# #+# */
|
||||||
/* Updated: 2025/04/23 15:33:00 by adjoly ### ########.fr */
|
/* Updated: 2025/04/23 16:00:14 by adjoly ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -47,11 +47,6 @@ int Server::_createSocket(std::string host, int port) {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fcntl(fd, F_SETFL, O_NONBLOCK) < 0) {
|
|
||||||
close(fd);
|
|
||||||
throw std::runtime_error("fcntl failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
int opt = 1;
|
int opt = 1;
|
||||||
if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)) < 0) {
|
if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)) < 0) {
|
||||||
close(fd);
|
close(fd);
|
||||||
|
Reference in New Issue
Block a user