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

test

parent a654219f
Loading
Loading
Loading
Loading
+59 −1
Changes for src/event/iocp.cpp: 59 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -312,6 +312,30 @@ namespace netplus {
        }
    }

    // -------------------------------------------------------------------------
    // Streaming re-trigger.  The app sets ResponsePending when it wants another
    // ResponseEvent but had nothing to queue yet (e.g. the upstream of a streamed
    // body had no bytes ready).  epoll/kqueue honour that by arming the writable
    // event, which fires again right away; IOCP has no such event, so post a
    // synthetic OP_RESPONSE completion instead.  It carries the SOCKET (not the
    // socket*) and uses key 0, so a connection torn down before it is dequeued is
    // simply not found again -- no dangling socket pointer.  When a write is still
    // in flight its OP_WRITE completion drives the next ResponseEvent itself.
    // Caller must hold c.event_mutex.
    // -------------------------------------------------------------------------
    static void post_response_kick(EventState* st, con& c) {
        if (c.slots.empty() || !c.slots[0].csock || c.slots[0].Closing.load()) return;
        if (c.SendData.pos < c.SendData.size() || c.slots[0].WritePending.load()) return;
        if (!c.slots[0].ResponsePending.exchange(false, std::memory_order_relaxed)) return;
        buffer* b = new buffer(1);
        b->operation = OP_RESPONSE;
        b->owner = reinterpret_cast<void*>(static_cast<uintptr_t>(c.slots[0].csock->fd()));
        if (!PostQueuedCompletionStatus(st->iocp, 0, 0, &b->overlapped)) {
            delete b;
            c.slots[0].ResponsePending.store(true, std::memory_order_relaxed);
        }
    }

    // -------------------------------------------------------------------------
    // init EventState for an event instance
    // -------------------------------------------------------------------------
@@ -478,6 +502,32 @@ namespace netplus {
                    }
                    if (!pov && key == 0) continue;

                    // Synthetic streaming re-trigger from post_response_kick().
                    if (pov && key == 0) {
                        buffer* kb = reinterpret_cast<buffer*>(
                            reinterpret_cast<char*>(pov) - offsetof(buffer, overlapped));
                        if (kb->operation != OP_RESPONSE) continue;
                        SOCKET ks = static_cast<SOCKET>(reinterpret_cast<uintptr_t>(kb->owner));
                        delete kb;
                        std::shared_ptr<con> kc = find_con(st, ks);
                        if (!kc) continue;
                        std::lock_guard<std::recursive_mutex> klock(kc->event_mutex);
                        if (!kc->slots[0].csock || kc->slots[0].Closing.load()) continue;
                        try {
                            if (kc->SendData.pos >= kc->SendData.size()
                                && !kc->slots[0].WritePending.load()
                                && !kc->slots[0].csock->hasPendingWrite()) {
                                ev->ResponseEvent(*kc, tid, 0);
                            }
                            if (kc->SendData.pos < kc->SendData.size())
                                try_post_send(ev, st, *kc, tid);
                            post_response_kick(st, *kc);
                        } catch (...) {
                            try_cleanup_con(ev, st, kc.get(), ks, tid);
                        }
                        continue;
                    }

                    socket* sockObj = reinterpret_cast<socket*>(key);
                    if (!sockObj) continue;

@@ -626,9 +676,11 @@ namespace netplus {
                            }
                        }

                        // Send queued data
                        // Send queued data; if the request handler asked for a
                        // streaming re-trigger without queueing anything, kick it.
                        try {
                            try_post_send(ev, st, *owner, tid);
                            post_response_kick(st, *owner);
                        } catch (...) {
                            owner->slots[0].ReadPending.store(false);
                            try_cleanup_con(ev, st, owner, cs, tid);
@@ -773,6 +825,12 @@ namespace netplus {
                                    }
                                }

                                // Still nothing to send but the app wants another
                                // turn (upstream not ready twice in a row): keep
                                // re-triggering like epoll's EPOLLOUT loop instead
                                // of parking the stream until the client speaks.
                                post_response_kick(st, *owner);

                                if (owner->SendData.pos >= owner->SendData.size() && !owner->slots[0].csock->hasPendingWrite() && !owner->slots[0].Closing.load()) {
                                    try { post_recv(st, *owner); } catch (...) {}
                                }
+7 −0
Changes for src/event/kqueue.cpp: 7 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -679,6 +679,13 @@ namespace netplus {
                                c->SendData.pos = 0;
                                evconnection->ResponseEvent(*c, tid, args);
                            }
                        } else if ((events & KQUEUE_EV_WRITE) && !needClose) {
                            // WRITE with no data queued -- KqueueArmGuard armed it
                            // because ResponsePending was set (and cleared it via
                            // exchange).  Call ResponseEvent so the app can produce
                            // the next chunk of a streamed response; without this a
                            // stream whose first fill came up empty never resumed.
                            evconnection->ResponseEvent(*c, tid, args);
                        }
                    }

+1 −1
Changes for src/socket.h: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -94,7 +94,7 @@ namespace netplus {
	enum sockettype { TCP = 0, UDP = 1, SSL = 2, QUIC = 3 };

#ifdef Windows
	enum IO_OPERATION { OP_READ = 0, OP_WRITE = 1 , OP_ACCEPT = 2 };
	enum IO_OPERATION { OP_READ = 0, OP_WRITE = 1 , OP_ACCEPT = 2, OP_RESPONSE = 3 };

	struct AcceptContext {
		WSAOVERLAPPED ov{};