Commit 1e973b85 authored by jan.koester's avatar jan.koester
Browse files

test helped with ki

parent 0dcd5667
Loading
Loading
Loading
Loading
+12 −21
Changes for src/event/iocp.cpp: 12 added lines, 21 removed lines.
Original line number Diff line number Diff line
@@ -56,8 +56,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

namespace netplus {

	std::mutex EventLock;

	class client {
	public:
		client(eventapi* eapi) {
@@ -77,38 +75,31 @@ namespace netplus {
	class poll {
	public:

		poll(HANDLE iocp,eventapi* api, socket* ssock) {
			g_iocp = iocp;
			g_eventapi = api;
			g_serversocket = ssock;
		};
		poll(HANDLE iocp, eventapi* api, socket* ssock)
			: g_iocp(iocp), g_eventapi(api), g_serversocket(ssock) {}

		void AddToClientList(client* pClientContext) {
			std::lock_guard<std::mutex> lock(EventLock);
			std::lock_guard<std::mutex> lock(g_ClientContextMutex);
			g_ClientContext.push_back(pClientContext);
		}

		bool AssociateWithIOCP(client* pClientContext) {
		void AssociateWithIOCP(client* pClientContext) {
			//Associate the socket with IOCP
			HANDLE giocp2 = CreateIoCompletionPort((HANDLE)(pClientContext)->CurCon->csock->fd(), g_iocp, (ULONG_PTR)pClientContext, 0);

			if (!giocp2 || g_iocp != giocp2) {
				RemoveFromClientList(pClientContext);
				std::cerr << "AssociateWithIOCP: " << GetLastError() << std::endl;
				return false;
				NetException exp;
				exp[NetException::Error] << "Error occurred while AssociateWithIOCP:  << GetLastError()";
				throw exp;
			}
			return true;
		}

		void RemoveFromClientList(client* pClientContext) {
			std::lock_guard<std::mutex> lock(EventLock);
			std::vector <client*>::iterator IterClientContext;
			for (IterClientContext = g_ClientContext.begin(); IterClientContext != g_ClientContext.end(); IterClientContext++) {
				if (pClientContext == *IterClientContext) {
					g_ClientContext.erase(IterClientContext);
			std::lock_guard<std::mutex> lock(g_ClientContextMutex);
			auto it = std::find(g_ClientContext.begin(), g_ClientContext.end(), pClientContext);
			if (it != g_ClientContext.end()) {
				g_ClientContext.erase(it);
				delete pClientContext;
					break;
				}
			}
		}

@@ -153,6 +144,7 @@ namespace netplus {
		socket*              g_serversocket;
		eventapi*            g_eventapi;
		std::vector<client*> g_ClientContext;
		std::mutex           g_ClientContextMutex; // NEU: mutex als Member
		friend class         client;
		friend class         EventWorker;
	};
@@ -275,7 +267,6 @@ namespace netplus {
						eargs->evpoll->RemoveFromClientList(pClientContext);
					}
					continue;

				}
			} // for
		}