Commit 644461cc authored by jan.koester's avatar jan.koester
Browse files
parents e5b48b6a 03f2fff6
Loading
Loading
Loading
Loading
+9 −9
Changes for src/event/iocp.cpp: 9 added lines, 9 removed lines.
Original line number Diff line number Diff line
@@ -248,17 +248,19 @@ namespace netplus {

				client* pClientContext = (client*)lpContext;

				if (!bReturn || dwBytesTransfered == 0) {
				if (!bReturn || bReturn && dwBytesTransfered == 0) {
					eargs->evpoll->RemoveFromClientList(pClientContext);
					continue;
				}

				if (!pClientContext->cltmtx.try_lock())
					continue;

				try {
					auto& curCon = pClientContext->CurCon;					

					switch (pClientContext->State) {
						case IO_WRITE_STATE: {
							std::lock_guard<std::mutex> lock(pClientContext->cltmtx);
							
							eargs->event->ResponseEvent(curCon, tid, args);

							ULONG ssize = curCon->SendData.size() < BLOCKSIZE ? (ULONG)curCon->SendData.size() : BLOCKSIZE;
@@ -269,7 +271,6 @@ namespace netplus {
								pClientContext->State = IO_READ_STATE;
						}break;
						case IO_READ_STATE: {
							std::lock_guard<std::mutex> lock(pClientContext->cltmtx);
							std::shared_ptr<char[]> buf(new char[BLOCKSIZE], std::default_delete<char[]>());
							size_t recv = curCon->csock->recvData(buf.get(), BLOCKSIZE, 0);
							curCon->RecvData.append(buf.get(), recv);
@@ -287,15 +288,14 @@ namespace netplus {
				} catch (NetException& e) {
					std::cerr << e.what() << std::endl;
					if (e.getErrorType() != NetException::Note) {
						continue;
					}
						eargs->evpoll->RemoveFromClientList(pClientContext);
					}
					
				} catch (...) {
					std::cerr << "unknown error close coonection !" << std::endl;
					eargs->evpoll->RemoveFromClientList(pClientContext);
					continue;
				}
				
				pClientContext->cltmtx.unlock();
			} // for
		}
	};
@@ -364,7 +364,7 @@ namespace netplus {
			throw exp;
		}

		if (SOCKET_ERROR == WSAEventSelect(_ServerSocket->fd(), g_hAcceptEvent, FD_ACCEPT | FD_READ | FD_WRITE)) {
		if (SOCKET_ERROR == WSAEventSelect(_ServerSocket->fd(), g_hAcceptEvent, FD_ACCEPT)) {
			NetException exp;
			exp[NetException::Error] << "Error occurred while WSAEventSelect().";
			WSACloseEvent(g_hAcceptEvent);
+14 −11
Changes for src/windows/tcp.cpp: 14 added lines, 11 removed lines.
Original line number Diff line number Diff line
@@ -206,16 +206,17 @@ size_t netplus::tcp::sendData(void* data, unsigned long size,int flags){

    if(rval == SOCKET_ERROR){
        DWORD lerror=GetLastError();

		int errortype = NetException::Error;
        if (lerror == WSA_IO_PENDING) {
            return (size_t)dwsend;
        } else {
            errortype = NetException::Note;
        } else if (lerror == WSAEWOULDBLOCK) {
            errortype = NetException::Note;
		}
        NetException exception;
            exception[NetException::Error] << "Socket senddata failed on Socket: " << (int)_Socket
        exception[errortype] << "Socket senddata failed on Socket: " << (int)_Socket
            << " ErrorMsg: " << lerror;
        throw exception;
    }
    }
    return (size_t)dwsend;
}

@@ -234,14 +235,16 @@ size_t netplus::tcp::recvData(void* data, unsigned long size,int flags){

    if(recvsize==SOCKET_ERROR){
        DWORD lerror = WSAGetLastError();

        if (lerror != WSA_IO_PENDING) {
            exception[NetException::Error] << "Socket recvdata failed on Socket: " << (int)_Socket
        int errortype = NetException::Error;
        if (lerror == WSA_IO_PENDING) {
            errortype = NetException::Note;
        }
        else if (lerror == WSAEWOULDBLOCK) {
            errortype = NetException::Note;
        }
        exception[errortype] << "Socket recvdata failed on Socket: " << (int)_Socket
            << " ErrorMsg: " << lerror;
        throw exception;
        } else {
            return dwBytes;
        }
    }

    return (size_t)dwBytes;