Commit 1f32e5b7 authored by jan.koester's avatar jan.koester
Browse files

test

parent eb28bc73
Loading
Loading
Loading
Loading
+19 −17
Changes for src/event/epoll.cpp: 19 added lines, 17 removed lines.
Original line number Diff line number Diff line
@@ -233,40 +233,41 @@ namespace netplus {
            if (!rcon || !rcon->csock) return;

            std::lock_guard<std::mutex> lk(rcon->event_mutex);
            if (!_Events[pos].data.ptr || !rcon->csock) return;
            if (!rcon->csock) return;

            try {
                bool gotAny = false;

                for (;;) {
                while (true) {
                    buffer buf(BLOCKSIZE);

                    size_t r = rcon->csock->recvData(buf, BLOCKSIZE); // kann Note werfen
                    size_t rcv = rcon->csock->recvData(buf);

                    if (r == 0) {
                        break;
                    if (rcv == 0) {
                        // In *your* API this might mean EAGAIN OR EOF depending on tcp::recvData implementation.
                        // If tcp::recvData is fixed to return 0 on EOF and throw Note on EAGAIN -> treat 0 as EOF.
                        NetException e;
                        e[NetException::Close] << "ReadEventHandler: EOF detected. Closing connection.";
                        throw e;
                    }

                    gotAny = true;
                    rcon->RecvData.append(buf.data.buf, r);
                    rcon->RecvData.append(buf.data.buf, rcv);
                    rcon->lasteventime = time(nullptr);

                    if (r < (size_t)BLOCKSIZE) break;
                }

                if (gotAny) {
                    // Let protocol layer consume as much as it can (HTTP parser / TLS state machine etc.)
                    evconnection->RequestEvent(*rcon, tid, args);
                }

                    if (!rcon->SendData.empty()) {
                        setpollEvents(pos, EPOLLOUT | EPOLLONESHOT);
                } else {
                    setpollEvents(pos, EPOLLIN | EPOLLONESHOT);
                }
                        return;
                    }

                    // continue loop: keep draining recv until would-block
                }
            } catch (NetException& e) {
                if (e.getErrorType() == NetException::Note) {
                    // would-block -> re-arm read (or write if you have pending output)
                    if (!rcon->SendData.empty())
                        setpollEvents(pos, EPOLLOUT | EPOLLONESHOT);
                    else
                        setpollEvents(pos, EPOLLIN | EPOLLONESHOT);
                    return;
                }
@@ -274,6 +275,7 @@ namespace netplus {
            }
        }


       void WriteEventHandler(int pos, const int tid, ULONG_PTR args) {
            con* wcon = reinterpret_cast<con*>(_Events[pos].data.ptr);
            if (!wcon || !wcon->csock) return;