Commit 5fc45ce9 authored by jan.koester's avatar jan.koester
Browse files

test

parent cc211813
Loading
Loading
Loading
Loading
+16 −12
Changes for src/ssl.cpp: 16 added lines, 12 removed lines.
Original line number Diff line number Diff line
@@ -406,23 +406,27 @@ void netplus::ssl::accept(std::unique_ptr<socket> &csock) {
    auto readExact = [&](uint8_t* dst, size_t n) {
        size_t got = 0;
        while (got < n) {
            buffer tmp(n - got); // owning buffer
            buffer b(n - got);                              // allocate writable buffer
            size_t r = 0;

            try {
                r = cssock->tcp::recvData(tmp);
            } catch (const netplus::NetException&) {
                throw;
            } catch (const std::exception& ex) {
                throwSSL(netplus::NetException::Error, std::string("recvData failed: ") + ex.what());
            } catch (...) {
                throwSSL(netplus::NetException::Error, "recvData failed (unknown exception)");
                r = cssock->tcp::recvData(b);
            } catch (netplus::NetException& e) {
                if (e.getErrorType() == netplus::NetException::Note) {
                    // EAGAIN/EWOULDBLOCK -> just retry (better: poll/select before retry)
                    std::this_thread::sleep_for(std::chrono::milliseconds(1));
                    continue;
                }
                throw; // real error
            }

            if (r == 0) {
                netplus::NetException e;
                e[netplus::NetException::Close] << "ssl::accept: connection closed while reading TLS record";
                throw e;
                NetException ex;
                ex[NetException::Close] << "TLS readExact: connection closed";
                throw ex;
            }
            std::memcpy(dst + got, tmp.data.buf, r);

            std::memcpy(dst + got, b.data.buf, r);          // copy from b.data.buf
            got += r;
        }
    };