
#include "Webserv.hpp"

void	Webserv::_accept_connection(int fd)
{
	struct sockaddr_in	addr;
	socklen_t 			addr_len;
	int					accepted_fd;

	std::cerr << "accept()\n";
	addr_len = sizeof addr;
	accepted_fd = ::accept(fd, (sockaddr*)&addr, &addr_len);
	if (accepted_fd == -1)
	{
		std::perror("err accept()");
		if (g_last_signal)
			_handle_last_signal();
		return ;
	}
	::fcntl(accepted_fd, F_SETFL, O_NONBLOCK);

	_clients.push_back(Client());
	_clients.back().fd = accepted_fd;

	_epoll_update(accepted_fd, EPOLLIN, EPOLL_CTL_ADD);
}
