Commit 93f96204 authored by jan.koester's avatar jan.koester
Browse files

stream support

parent fd436377
Loading
Loading
Loading
Loading
+46 −0
Original line number Diff line number Diff line
@@ -111,3 +111,49 @@ netplus::con::con(eventapi *event)
netplus::con::~con(){
}

bool netplus::con::flushSendData(){
    std::lock_guard<std::recursive_mutex> lk(event_mutex);

    if (slots.empty() || !slots[0].csock)
        return true;

    if (slots[0].csock->hasPendingWrite()) {
        try {
            slots[0].csock->flush_out();
        } catch (NetException &e) {
            if (e.getErrorType() == NetException::Note)
                return false;
            throw;
        }
    }

    while (SendData.pos < SendData.size()) {
        size_t remaining = SendData.size() - SendData.pos;
        size_t sendlen = (std::min)((size_t)BLOCKSIZE, remaining);
        buffer out(SendData.data() + SendData.pos, sendlen);

        size_t consumed = 0;
        try {
            consumed = slots[0].csock->sendData(out, 0);
            if (consumed == 0)
                return false;
            SendData.pos += consumed;
            if (SendData.pos >= SendData.size()) {
                SendData.clear();
                SendData.pos = 0;
            } else if (SendData.pos > BLOCKSIZE * 4) {
                SendData.erase(SendData.begin(), SendData.begin() + SendData.pos);
                SendData.pos = 0;
            }
            if (slots[0].csock->hasPendingWrite())
                slots[0].csock->flush_out();
        } catch (NetException &e) {
            if (e.getErrorType() == NetException::Note)
                return false;
            throw;
        }
    }

    return true;
}
+9 −0
Original line number Diff line number Diff line
@@ -190,6 +190,15 @@ namespace netplus {
            std::recursive_mutex event_mutex;

             time_t lasteventime;

            // Proactively write out whatever is currently queued in SendData,
            // instead of waiting for the event loop's post-RequestEvent drain.
            // Safe to call from within a RequestEvent handler on the same
            // thread (re-locks event_mutex, which is recursive). Returns true
            // if SendData was fully drained, false if the socket would block
            // (caller may retry later; the framework's normal EPOLLOUT re-arm
            // still applies for whatever's left queued).
            bool flushSendData();
        protected:
            con();
            friend class poll;