Commit 6a8a3e8d authored by jan.koester's avatar jan.koester
Browse files

test

parent 8c79b2d8
Loading
Loading
Loading
Loading
+22 −36
Original line number Diff line number Diff line
@@ -154,40 +154,26 @@ namespace netplus {

    class EventWorker {
    public:
        static void start_read(client* ctx) {
            DWORD flags = 0;
            DWORD bytesRecv = 0;
            memset(&ctx->readCtx.overlapped, 0, sizeof(WSAOVERLAPPED));

            int ret = WSARecv(ctx->CurCon->csock->fd(), &ctx->readCtx.wsaBuf, 1,
                              &bytesRecv, &flags, &ctx->readCtx.overlapped, NULL);

            if (ret == SOCKET_ERROR && WSAGetLastError() != WSA_IO_PENDING) {
                NetException exp;
                exp[NetException::Error] << "WSARecv failed: " << WSAGetLastError();
                throw exp;
		// Inside the IOCP Worker logic
		void EventWorker::start_read(client* ctx) {
			con& c = *ctx->CurCon;
			buffer buf(ctx->readCtx.buffer, BLOCKSIZE);

			if (c.csock->_Type == sockettype::UDP) {
				// Cast to UDP to access the WSA-specific methods
				static_cast<udp*>(c.csock.get())->recvDataWSA(buf, 0);
			}
		}

        static void start_write(client* ctx) {
		void EventWorker::start_write(client* ctx) {
			con& c = *ctx->CurCon;
			if (c.SendData.empty()) return;

            // Prepare buffer for WSASend
			size_t toSend = std::min<size_t>(BLOCKSIZE, c.SendData.size());
            memcpy(ctx->writeCtx.buffer, c.SendData.data(), toSend);
            ctx->writeCtx.wsaBuf.len = (ULONG)toSend;

            memset(&ctx->writeCtx.overlapped, 0, sizeof(WSAOVERLAPPED));
            DWORD bytesSent = 0;

            int ret = WSASend(c.csock->fd(), &ctx->writeCtx.wsaBuf, 1,
                              &bytesSent, 0, &ctx->writeCtx.overlapped, NULL);
			buffer out(c.SendData.data(), toSend);

            if (ret == SOCKET_ERROR && WSAGetLastError() != WSA_IO_PENDING) {
                NetException exp;
                exp[NetException::Error] << "WSASend failed: " << WSAGetLastError();
                throw exp;
			if (c.csock->_Type == sockettype::UDP) {
				static_cast<udp*>(c.csock.get())->sendDataWSA(out, 0);
			}
		}