<body>
<section class="notFound">
<div class="img">
<img src="https://assets.codepen.io/5647096/backToTheHomepage.png" alt="Back to the Homepage"/>
<img src="https://assets.codepen.io/5647096/Delorean.png" alt="El Delorean, El Doc y Marti McFly"/>
</div>
<div class="text">
<h1>404</h1>
<h2>PAGE NOT FOUND</h2>
<h3>BACK TO HOME?</h3>
<a href="#" class="yes">YES</a>
<a href="https://www.youtube.com/watch?v=G3AfIvJBcGo">NO</a>
</div>
</section>
</body>
class Socket {
public:
Socket();
Socket(int fd);
Socket(const std::string& adr, int port);
Socket(const Socket& ref);
~Socket();
operator int();
Socket& operator=(const Socket& rhs);
Socket& operator=(int fd);
void bindHost();
int getFd() const;
void hostListen(unsigned queue);
static Socket* acceptConnection(int host);
class FailOnSocket : public std::exception {
public:
virtual const char* what() const throw();
};
protected:
int _socket;
sockaddr_in _info;
};
#include "../includes/Socket.hpp"
#include <iostream>
ft::Socket::Socket() : _socket(123) {} // check
ft::Socket::Socket(int fd) : _socket(fd) {}
ft::Socket::Socket(const Socket& ref) { *this = ref; }
ft::Socket::Socket(const std::string& adr, int port) {
if ((_socket = socket(PF_INET, SOCK_STREAM, 0)) < 0)
throw ft::Socket::FailOnSocket();
_info.sin_addr.s_addr = inet_addr(adr.c_str());
_info.sin_family = PF_INET;
_info.sin_len = 0;
if (_info.sin_addr.s_addr == static_cast<in_addr_t>(-1)) {
close(_socket);
throw ft::Socket::FailOnSocket();
}
_info.sin_port = static_cast<in_port_t>(htons(port));
if (fcntl(_socket, F_SETFL, O_NONBLOCK) < 0) {
close(_socket);
throw ft::Socket::FailOnSocket();
}
}
ft::Socket::~Socket() { close(_socket); }
ft::Socket& ft::Socket::operator=(const Socket& ref) {
if (this == &ref)
return *this;
close(_socket);
_socket = ref._socket;
memcpy(&_info, &ref._info, sizeof(ref._info));
return *this;
}
ft::Socket& ft::Socket::operator=(int fd) {
_socket = fd;
return *this;
}
ft::Socket* ft::Socket::acceptConnection(int host) {
ft::Socket* t = new ft::Socket;
sockaddr_storage st;
int flags = fcntl(*t, F_GETFL, 0);
fcntl(*t, F_SETFL, flags | O_NONBLOCK);
int len = sizeof(st);
*t = accept(host, (struct sockaddr*)&st, (socklen_t*)&len);
if (*t < 0)
throw ft::Socket::FailOnSocket();
return t;
}
void ft::Socket::bindHost() {
if (bind(_socket, (const sockaddr*)&_info, sizeof(_info)) == -1) {
throw ft::Socket::FailOnSocket();
}
}
void ft::Socket::hostListen(unsigned queue) {
if (listen(_socket, queue) < 0)
throw ft::Socket::FailOnSocket();
}
ft::Socket::operator int() { return _socket; }
const char* ft::Socket::FailOnSocket::what() const throw() {
return "Broken socket";
}
int ft::Socket::getFd() const {
return this->_socket;
}
// bool ft::operator==(const Socket& lhs, const Socket& rhs) {
// return lhs.getFd() == rhs.getFd();
// }
// Висит на этом месте
int newEvents = kevent(kq, NULL, 0, tEvent, 32, NULL);
for (int i = 0; i < newEvents; i++) { // цикл который я выше отправил
smart_ptr(int t[]) {
_ptr = &(t[0]); //вставляю эту строку
// выходит такая ошибка: incompatible pointer types assigning to 'int *[]' from 'int *'
}
memcpy(&workingSet, &masterSet, sizeof(masterSet));
std::cout << "Waiting new connection... max fd" << maxFd << std::endl;
fdReady = select(maxFd + 1, &workingSet, NULL, NULL, NULL);
if (fdReady < 0)
break ;
for (int fd = 0; fd <= maxFd && fdReady > 0; ++fd) {
if (FD_ISSET(fd, &workingSet)) {
fdReady--;
if (fd == _hostSock->getSocket()) {
do {
newFd = accept(_hostSock->getSocket(), NULL, NULL);
FD_SET(newFd, &masterSet);
if (newFd > maxFd)
maxFd = newFd;
} while (newFd != -1);
} else {
_handleConnect(masterSet, fd, maxFd);
}
}
fdReady = select(maxFd + 1, &workingSet, NULL, NULL, NULL);