Commit 42eb6042 authored by jan.koester's avatar jan.koester
Browse files

test

parent bc8e0c4c
Loading
Loading
Loading
Loading
+10 −14
Original line number Diff line number Diff line
@@ -173,41 +173,37 @@ namespace netplus {
            NetException exception;

            // 1) Create as unique_ptr to satisfy the API requirement
            std::shared_ptr<con> ucon;
            evconnection->CreateConnection(ucon);
            std::shared_ptr<con> ccon;
            evconnection->CreateConnection(ccon);

            if (!ucon) {
            if (!ccon) {
                std::cerr << "ConnectEventHandler: CreateConnection returned null\n";
                return;
            }

            // 2) Initialize socket (TCP, UDP, or SSL)
            if (_ServerSocket->_Type == sockettype::TCP) {
                ucon->csock = std::make_unique<tcp>(-1);
                ccon->csock = std::make_unique<tcp>(-1);
            } else if (_ServerSocket->_Type == sockettype::UDP) {
                ucon->csock = std::make_unique<udp>(-1);
                ccon->csock = std::make_unique<udp>(-1);
            } else if (_ServerSocket->_Type == sockettype::SSL) {
                netplus::ssl* srv = static_cast<netplus::ssl*>(_ServerSocket);
                ucon->csock = std::make_unique<ssl>(srv->_cert, -1);
                ccon->csock = std::make_unique<ssl>(srv->_cert, -1);
            } else {
                exception[NetException::Error] << "ConnectEventHandler: unsupported socket type";
                throw exception;
            }

            // 3) Accept and Set Nonblocking
            _ServerSocket->accept(ucon->csock);
            _ServerSocket->accept(ccon->csock);
            try {
                ucon->csock->setFlag(O_NONBLOCK, 1);
                ccon->csock->setFlag(O_NONBLOCK, 1);
            } catch (NetException& e) {
                try { ucon->csock->close(); } catch (...) {}
                try { ccon->csock->close(); } catch (...) {}
                throw;
            }

            ucon->lasteventime = time(nullptr);

            // 4) Transfer ownership to shared_ptr for global management
            // This allows the map to hold the object even if ucon goes out of scope.
            std::shared_ptr<con> ccon(ucon.release());
            ccon->lasteventime = time(nullptr);

            con* raw = ccon.get();
            int fd = ccon->csock->fd();