Commit f2a0b489 authored by jan.koester's avatar jan.koester
Browse files

test

parent 4f1d8ad7
Loading
Loading
Loading
Loading
+12 −28
Original line number Diff line number Diff line
@@ -183,40 +183,24 @@ namespace netplus {
                ccon->csock=std::make_unique<ssl>( srv->_cert,-1);
            }

            try {
            _ServerSocket->accept(ccon->csock);
            } catch (NetException& e) {
                if (e.getErrorType() == NetException::Note) return;
                throw e;
            }

            ccon->csock->setFlag(O_NONBLOCK, 1);
            ccon->csock->setNonBlock();

            // 3) Bridge to shared_ptr
            ccon->lasteventime = time(nullptr);
            int fd = ccon->csock->fd();

            {
                std::lock_guard<std::mutex> glk(POLL_HANDLER_MUTEX);
                CONNECTIONS.emplace(fd, ccon); // nicht std::move
            }

            // 4) Register with Epoll
            struct epoll_event setevent = {0};
            // We use EPOLLET (Edge Triggered) and EPOLLONESHOT for thread safety
            setevent.events = EPOLLIN | EPOLLOUT | EPOLLRDHUP | EPOLLONESHOT | EPOLLET;
            setevent.data.fd = ccon->csock->fd();
            setevent.events = EPOLLIN | EPOLLRDHUP | EPOLLONESHOT | EPOLLET; // kein EPOLLOUT
            setevent.data.fd = fd;

            if (epoll_ctl(_pollFD, EPOLL_CTL_ADD, ccon->csock->fd(), &setevent) < 0) {
                if (errno == EAGAIN || errno == EWOULDBLOCK) {
                    return;
                }
                char errstr[255];
                strerror_r_netplus(errno, errstr, 255);
                exception[NetException::Error] << "ConnectEventHandler: epoll_ctl add failed: " << errstr;
                throw exception;
            }
            epoll_ctl(_pollFD, EPOLL_CTL_ADD, fd, &setevent);

            evconnection->ConnectEvent(*ccon, tid, args);

            {
                std::lock_guard<std::mutex> glk(POLL_HANDLER_MUTEX);
                CONNECTIONS.emplace(ccon->csock->fd(), std::move(ccon));
            }
        }

        void ReadEventHandler(int pos, const int tid, ULONG_PTR args) {