Answer the question
In order to leave comments, you need to log in
Why breaks the connection when changing the type?
Good afternoon!
I wrote my class:
ft::Socket::Socket(int fd) : _socket(fd) {}
ft::Socket::operator int() { return _socket; }
for (int i = 0; i < newEvents; i++) {
// Если здесь поменять int на ft::Socket
int fd(tEvent[i].ident);
std::cerr << fd << "\n";
if (tEvent[i].flags & EV_EOF) {
std::cerr << "Connection close from remote host\n";
close((int)fd);
} else if (fd == _hostSock) {
std::cerr << "New connection ";
struct sockaddr_storage remoteAdr;
socklen_t size = sizeof(remoteAdr);
int newSock = accept((int)fd, (struct sockaddr *)&remoteAdr, &size);
if (newSock == -1)
std::cerr << "error: Cant accept new connection\n";
EV_SET(&event, newSock, EVFILT_READ, EV_ADD, 0, 0, NULL);
kevent(kq, &event, 1, NULL, 0, NULL);
std::cerr << "connection accepted\n";
int flags = fcntl(newSock, F_GETFL, 0);
if (fcntl(newSock, F_SETFL, flags | O_NONBLOCK) < 0)
std::cerr << "Cant set socket to nonblock statement";
EV_SET(&event, newSock, EVFILT_WRITE, EV_ADD | EV_ONESHOT, 0, 0, NULL);
kevent(kq, &event, 1, NULL, 0, NULL);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question