Commit 2df4ee51 authored by jan.koester's avatar jan.koester
Browse files

test

parent 0350512d
Loading
Loading
Loading
Loading
+17 −12
Changes for src/event/iocp.cpp: 17 added lines, 12 removed lines.
Original line number Diff line number Diff line
@@ -57,8 +57,7 @@ namespace netplus {

	enum IOState {
		IO_READ_STATE = 0,
		IO_WRITE_STATE = 1,
		IO_CLOSE_STATE = 2
		IO_WRITE_STATE = 1
	};

	class client {
@@ -265,6 +264,7 @@ namespace netplus {
							try {
								eargs->event->ResponseEvent(*curCon, tid, args);
							} catch (...) {
								curCon->SendData.pos = 0;
								curCon->SendData.clear();
							}
	
@@ -287,7 +287,7 @@ namespace netplus {
							// Erase the sent data from the beginning of the buffer
							curCon->SendData.resize(ret);
							if (curCon->SendData.empty()) {
								pClientContext->State = IO_CLOSE_STATE;
								pClientContext->State = IO_READ_STATE;
							} else {
								continue;
							}
@@ -314,6 +314,7 @@ namespace netplus {
							try{
								eargs->event->RequestEvent(*curCon, tid, args);
							} catch (...){
								curCon->RecvData.pos = 0;
								curCon->RecvData.clear();
							}
							
@@ -322,12 +323,6 @@ namespace netplus {
								continue;
							}
						}break;
						case IO_CLOSE_STATE: {
							eargs->event->DisconnectEvent(*curCon, tid, args);
							delete curCon->csock;
							delete pClientContext;
							
						} break;
						default: {
							NetException exp;
							exp[NetException::Error] << "Unknown IO state: " << pClientContext->State;
@@ -420,15 +415,25 @@ namespace netplus {
		}

		for (;;) {
			if (WSA_WAIT_FAILED != WSAWaitForMultipleEvents(1, &g_hAcceptEvent, FALSE, WSA_INFINITE, FALSE)) {

			if (SOCKET_ERROR == WSAEventSelect(_ServerSocket->fd(), g_hAcceptEvent, FD_ACCEPT)) {
				NetException exp;
				exp[NetException::Error] << "Error occurred while WSAEventSelect().";
				WSACloseEvent(g_hAcceptEvent);
				throw exp;
			}

			// Now, call WSAEnumNetworkEvents to get the details and reset the event.
			WSAEnumNetworkEvents(_ServerSocket->fd(), g_hAcceptEvent, &WSAEvents);

			// Check for FD_ACCEPT event and its error code.
			if ((WSAEvents.lNetworkEvents & FD_ACCEPT) && (0 == WSAEvents.iErrorCode[FD_ACCEPT_BIT])) {
				// Handle the successful connection.
				try {
					evpoll.AcceptConnection(lpfnAcceptEx, 0, args);
				}
				catch (NetException& e) {
						std::cerr << e.what() << std::endl;
					}
					std::cerr << "AcceptConnection error: " << e.what() << std::endl;
				}
			}
		}