X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fsocketengines%2Fsocketengine_select.cpp;h=441fe494a54a40e8d77028abe18fb2a25c7d6e40;hb=196b9a9fb6878bdf686ab4e3bbdef2d1c26fe366;hp=eacfc0fbf1be46e0e871a66c020a98cca7e5d52a;hpb=810c662c9b55908101ca085293c52c3239ef22d1;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/socketengines/socketengine_select.cpp b/src/socketengines/socketengine_select.cpp index eacfc0fbf..441fe494a 100644 --- a/src/socketengines/socketengine_select.cpp +++ b/src/socketengines/socketengine_select.cpp @@ -1,22 +1,49 @@ -/* +------------------------------------+ - * | Inspire Internet Relay Chat Daemon | - * +------------------------------------+ +/* + * InspIRCd -- Internet Relay Chat Daemon * - * InspIRCd: (C) 2002-2009 InspIRCd Development Team - * See: http://wiki.inspircd.org/Credits + * Copyright (C) 2009 Daniel De Graaf + * Copyright (C) 2007-2008 Craig Edwards * - * This program is free but copyrighted software; see - * the file COPYING for details. + * This file is part of InspIRCd. InspIRCd is free software: you can + * redistribute it and/or modify it under the terms of the GNU General Public + * License as published by the Free Software Foundation, version 2. * - * --------------------------------------------------- + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ + +#include "inspircd_config.h" + #include "inspircd.h" +#include "socketengine.h" + #ifndef WINDOWS #include #endif // WINDOWS -#include "socketengines/socketengine_select.h" +/** A specialisation of the SocketEngine class, designed to use traditional select(). + */ +class SelectEngine : public SocketEngine +{ +public: + /** Create a new SelectEngine + */ + SelectEngine(); + /** Delete a SelectEngine + */ + virtual ~SelectEngine(); + virtual bool AddFd(EventHandler* eh, int event_mask); + virtual void DelFd(EventHandler* eh); + void OnSetEvent(EventHandler* eh, int, int); + virtual int DispatchEvents(); + virtual std::string GetName(); +}; SelectEngine::SelectEngine() { @@ -32,7 +59,7 @@ SelectEngine::~SelectEngine() delete[] ref; } -bool SelectEngine::AddFd(EventHandler* eh, int) +bool SelectEngine::AddFd(EventHandler* eh, int event_mask) { int fd = eh->GetFd(); if ((fd < 0) || (fd > GetMaxFds() - 1)) @@ -49,18 +76,17 @@ bool SelectEngine::AddFd(EventHandler* eh, int) return true; } -bool SelectEngine::DelFd(EventHandler* eh, bool force) +void SelectEngine::DelFd(EventHandler* eh) { int fd = eh->GetFd(); if ((fd < 0) || (fd > GetMaxFds() - 1)) - return false; + return; CurrentSetSize--; ref[fd] = NULL; ServerInstance->Logs->Log("SOCKET",DEBUG,"Remove file descriptor: %d", fd); - return true; } void SelectEngine::OnSetEvent(EventHandler* eh, int old_mask, int new_mask) @@ -80,8 +106,8 @@ int SelectEngine::DispatchEvents() FD_ZERO(&rfdset); FD_ZERO(&errfdset); - /* Populate the select FD sets (this is why select sucks compared to epoll, kqueue, IOCP) */ - for (int i = 0; i < FD_SETSIZE; i++) + /* Populate the select FD sets (this is why select sucks compared to epoll, kqueue) */ + for (unsigned int i = 0; i < FD_SETSIZE; i++) { EventHandler* eh = ref[i]; if (!eh) @@ -99,6 +125,7 @@ int SelectEngine::DispatchEvents() tval.tv_usec = 0; sresult = select(FD_SETSIZE, &rfdset, &wfdset, &errfdset, &tval); + ServerInstance->UpdateTime(); /* Nothing to process this time around */ if (sresult < 1) @@ -128,13 +155,15 @@ int SelectEngine::DispatchEvents() if (FD_ISSET (i, &rfdset)) { ReadEvents++; - SetEventMask(eh, eh->GetEventMask() & ~FD_READ_WILL_BLOCK); + SetEventMask(ev, ev->GetEventMask() & ~FD_READ_WILL_BLOCK); ev->HandleEvent(EVENT_READ); + if (ev != ref[i]) + continue; } if (FD_ISSET (i, &wfdset)) { WriteEvents++; - SetEventMask(eh, eh->GetEventMask() & ~(FD_WRITE_WILL_BLOCK | FD_WANT_SINGLE_WRITE)); + SetEventMask(ev, ev->GetEventMask() & ~(FD_WRITE_WILL_BLOCK | FD_WANT_SINGLE_WRITE)); ev->HandleEvent(EVENT_WRITE); } } @@ -148,3 +177,8 @@ std::string SelectEngine::GetName() { return "select"; } + +SocketEngine* CreateSocketEngine() +{ + return new SelectEngine; +}