From da812566e80811b7f9a190feb0913464ba9f0069 Mon Sep 17 00:00:00 2001 From: Adam Date: Tue, 4 Feb 2014 22:44:20 +0100 Subject: Coding style changes in socketengines --- src/socketengine.cpp | 2 +- src/socketengines/socketengine_epoll.cpp | 6 +-- src/socketengines/socketengine_kqueue.cpp | 9 ++-- src/socketengines/socketengine_poll.cpp | 7 ---- src/socketengines/socketengine_ports.cpp | 10 +---- src/socketengines/socketengine_select.cpp | 69 +++++++++++++++---------------- 6 files changed, 41 insertions(+), 62 deletions(-) diff --git a/src/socketengine.cpp b/src/socketengine.cpp index c2a357b38..43e2c6f20 100644 --- a/src/socketengine.cpp +++ b/src/socketengine.cpp @@ -121,7 +121,7 @@ bool SocketEngine::HasFd(int fd) EventHandler* SocketEngine::GetRef(int fd) { if (fd < 0 || static_cast(fd) >= ref.size()) - return 0; + return NULL; return ref[fd]; } diff --git a/src/socketengines/socketengine_epoll.cpp b/src/socketengines/socketengine_epoll.cpp index 8f5066c22..af58cb026 100644 --- a/src/socketengines/socketengine_epoll.cpp +++ b/src/socketengines/socketengine_epoll.cpp @@ -123,7 +123,7 @@ bool EPollEngine::AddFd(EventHandler* eh, int event_mask) } struct epoll_event ev; - memset(&ev,0,sizeof(ev)); + memset(&ev, 0, sizeof(ev)); ev.events = mask_to_epoll(event_mask); ev.data.fd = fd; int i = epoll_ctl(EngineHandle, EPOLL_CTL_ADD, fd, &ev); @@ -150,7 +150,7 @@ void EPollEngine::OnSetEvent(EventHandler* eh, int old_mask, int new_mask) { // ok, we actually have something to tell the kernel about struct epoll_event ev; - memset(&ev,0,sizeof(ev)); + memset(&ev, 0, sizeof(ev)); ev.events = new_events; ev.data.fd = eh->GetFd(); epoll_ctl(EngineHandle, EPOLL_CTL_MOD, eh->GetFd(), &ev); @@ -167,7 +167,7 @@ void EPollEngine::DelFd(EventHandler* eh) } struct epoll_event ev; - memset(&ev,0,sizeof(ev)); + memset(&ev, 0, sizeof(ev)); ev.data.fd = fd; int i = epoll_ctl(EngineHandle, EPOLL_CTL_DEL, fd, &ev); diff --git a/src/socketengines/socketengine_kqueue.cpp b/src/socketengines/socketengine_kqueue.cpp index 8c27b29b2..81addd1c2 100644 --- a/src/socketengines/socketengine_kqueue.cpp +++ b/src/socketengines/socketengine_kqueue.cpp @@ -176,10 +176,9 @@ void KQueueEngine::OnSetEvent(EventHandler* eh, int old_mask, int new_mask) struct kevent ke; EV_SET(&ke, eh->GetFd(), EVFILT_WRITE, EV_ADD, 0, 0, NULL); int i = kevent(EngineHandle, &ke, 1, 0, 0, NULL); - if (i < 0) { + if (i < 0) ServerInstance->Logs->Log("SOCKET", LOG_DEFAULT, "Failed to mark for writing: %d %s", eh->GetFd(), strerror(errno)); - } } else if ((old_mask & FD_WANT_POLL_WRITE) && !(new_mask & FD_WANT_POLL_WRITE)) { @@ -187,10 +186,9 @@ void KQueueEngine::OnSetEvent(EventHandler* eh, int old_mask, int new_mask) struct kevent ke; EV_SET(&ke, eh->GetFd(), EVFILT_WRITE, EV_DELETE, 0, 0, NULL); int i = kevent(EngineHandle, &ke, 1, 0, 0, NULL); - if (i < 0) { + if (i < 0) ServerInstance->Logs->Log("SOCKET", LOG_DEFAULT, "Failed to mark for writing: %d %s", eh->GetFd(), strerror(errno)); - } } if ((new_mask & (FD_WANT_FAST_WRITE | FD_WANT_SINGLE_WRITE)) && !(old_mask & (FD_WANT_FAST_WRITE | FD_WANT_SINGLE_WRITE))) { @@ -198,10 +196,9 @@ void KQueueEngine::OnSetEvent(EventHandler* eh, int old_mask, int new_mask) struct kevent ke; EV_SET(&ke, eh->GetFd(), EVFILT_WRITE, EV_ADD | EV_ONESHOT, 0, 0, NULL); int i = kevent(EngineHandle, &ke, 1, 0, 0, NULL); - if (i < 0) { + if (i < 0) ServerInstance->Logs->Log("SOCKET", LOG_DEFAULT, "Failed to mark for writing: %d %s", eh->GetFd(), strerror(errno)); - } } } diff --git a/src/socketengines/socketengine_poll.cpp b/src/socketengines/socketengine_poll.cpp index 0112b7d2f..722555510 100644 --- a/src/socketengines/socketengine_poll.cpp +++ b/src/socketengines/socketengine_poll.cpp @@ -21,9 +21,6 @@ */ -#ifndef SOCKETENGINE_POLL -#define SOCKETENGINE_POLL - #include #include #include @@ -44,8 +41,6 @@ # define poll WSAPoll #endif -class InspIRCd; - /** A specialisation of the SocketEngine class, designed to use poll(). */ class PollEngine : public SocketEngine @@ -68,8 +63,6 @@ public: virtual std::string GetName(); }; -#endif - PollEngine::PollEngine() : events(1), fd_mappings(1) { CurrentSetSize = 0; diff --git a/src/socketengines/socketengine_ports.cpp b/src/socketengines/socketengine_ports.cpp index 936a8f6b9..569155021 100644 --- a/src/socketengines/socketengine_ports.cpp +++ b/src/socketengines/socketengine_ports.cpp @@ -20,10 +20,6 @@ #include "inspircd.h" #include "exitcodes.h" -#include - -#ifndef SOCKETENGINE_PORTS -#define SOCKETENGINE_PORTS #ifndef __sun # error You need Solaris 10 or later to make use of this code. @@ -36,6 +32,7 @@ #include "socketengine.h" #include #include +#include /** A specialisation of the SocketEngine class, designed to use solaris 10 I/O completion ports */ @@ -60,11 +57,6 @@ public: virtual std::string GetName(); }; -#endif - - -#include - PortsEngine::PortsEngine() : events(1) { int max = ulimit(4, 0); diff --git a/src/socketengines/socketengine_select.cpp b/src/socketengines/socketengine_select.cpp index 39cfb7789..82fe0bb6b 100644 --- a/src/socketengines/socketengine_select.cpp +++ b/src/socketengines/socketengine_select.cpp @@ -125,51 +125,48 @@ int SelectEngine::DispatchEvents() int sresult = select(MaxFD + 1, &rfdset, &wfdset, &errfdset, &tval); ServerInstance->UpdateTime(); - /* Nothing to process this time around */ - if (sresult < 1) - return 0; - for (int i = 0, j = sresult; i <= MaxFD && j > 0; i++) { int has_read = FD_ISSET(i, &rfdset), has_write = FD_ISSET(i, &wfdset), has_error = FD_ISSET(i, &errfdset); - if (has_read || has_write || has_error) - { - --j; + if (!(has_read || has_write || has_error)) + continue; - EventHandler* ev = GetRef(i); - if (!ev) - continue; + --j; - if (has_error) - { - ErrorEvents++; + EventHandler* ev = GetRef(i); + if (!ev) + continue; - socklen_t codesize = sizeof(int); - int errcode = 0; - if (getsockopt(i, SOL_SOCKET, SO_ERROR, (char*)&errcode, &codesize) < 0) - errcode = errno; + if (has_error) + { + ErrorEvents++; + + socklen_t codesize = sizeof(int); + int errcode = 0; + if (getsockopt(i, SOL_SOCKET, SO_ERROR, (char*)&errcode, &codesize) < 0) + errcode = errno; - ev->HandleEvent(EVENT_ERROR, errcode); + ev->HandleEvent(EVENT_ERROR, errcode); + continue; + } + + if (has_read) + { + ReadEvents++; + SetEventMask(ev, ev->GetEventMask() & ~FD_READ_WILL_BLOCK); + ev->HandleEvent(EVENT_READ); + if (ev != GetRef(i)) continue; - } - - if (has_read) - { - ReadEvents++; - SetEventMask(ev, ev->GetEventMask() & ~FD_READ_WILL_BLOCK); - ev->HandleEvent(EVENT_READ); - if (ev != GetRef(i)) - continue; - } - if (has_write) - { - WriteEvents++; - int newmask = (ev->GetEventMask() & ~(FD_WRITE_WILL_BLOCK | FD_WANT_SINGLE_WRITE)); - this->OnSetEvent(ev, ev->GetEventMask(), newmask); - SetEventMask(ev, newmask); - ev->HandleEvent(EVENT_WRITE); - } + } + + if (has_write) + { + WriteEvents++; + int newmask = (ev->GetEventMask() & ~(FD_WRITE_WILL_BLOCK | FD_WANT_SINGLE_WRITE)); + this->OnSetEvent(ev, ev->GetEventMask(), newmask); + SetEventMask(ev, newmask); + ev->HandleEvent(EVENT_WRITE); } } -- cgit v1.2.3