1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2008 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
14 /* $Core: libIRCDsocketengine */
16 /********* DEFAULTS **********/
17 /* $ExtraSources: socketengines/socketengine_select.cpp */
18 /* $ExtraObjects: socketengine_select.o */
21 /* $ExtraSources: socketengines/socketengine_kqueue.cpp */
22 /* $ExtraObjects: socketengine_kqueue.o */
26 /* $ExtraSources: socketengines/socketengine_epoll.cpp */
27 /* $ExtraObjects: socketengine_epoll.o */
31 /* $ExtraSources: socketengines/socketengine_ports.cpp */
32 /* $ExtraObjects: socketengine_ports.o */
36 #include "socketengine.h"
38 int EventHandler::GetFd()
43 void EventHandler::SetFd(int FD)
48 bool EventHandler::Readable()
53 bool EventHandler::Writeable()
58 void SocketEngine::WantWrite(EventHandler* eh)
62 SocketEngine::SocketEngine(InspIRCd* Instance) : ServerInstance(Instance)
64 TotalEvents = WriteEvents = ReadEvents = ErrorEvents = 0;
67 SocketEngine::~SocketEngine()
71 bool SocketEngine::AddFd(EventHandler* eh)
76 bool SocketEngine::HasFd(int fd)
78 if ((fd < 0) || (fd > MAX_DESCRIPTORS))
83 EventHandler* SocketEngine::GetRef(int fd)
85 if ((fd < 0) || (fd > MAX_DESCRIPTORS))
90 bool SocketEngine::DelFd(EventHandler* eh, bool force)
95 int SocketEngine::GetMaxFds()
100 int SocketEngine::GetRemainingFds()
105 int SocketEngine::DispatchEvents()
110 std::string SocketEngine::GetName()
112 return "misconfigured";
115 bool SocketEngine::BoundsCheckFd(EventHandler* eh)
119 if ((eh->GetFd() < 0) || (eh->GetFd() > MAX_DESCRIPTORS))
125 int SocketEngine::Accept(EventHandler* fd, sockaddr *addr, socklen_t *addrlen)
127 return accept(fd->GetFd(), addr, addrlen);
130 int SocketEngine::Close(EventHandler* fd)
133 return closesocket(fd->GetFd());
135 return close(fd->GetFd());
139 int SocketEngine::Close(int fd)
142 return closesocket(fd);
148 int SocketEngine::Blocking(int fd)
151 unsigned long opt = 0;
152 return ioctlsocket(fd, FIONBIO, &opt);
154 int flags = fcntl(fd, F_GETFL, 0);
155 return fcntl(fd, F_SETFL, flags ^ O_NONBLOCK);
159 int SocketEngine::NonBlocking(int fd)
162 unsigned long opt = 1;
163 return ioctlsocket(fd, FIONBIO, &opt);
165 int flags = fcntl(fd, F_GETFL, 0);
166 return fcntl(fd, F_SETFL, flags | O_NONBLOCK);
170 int SocketEngine::GetSockName(EventHandler* fd, sockaddr *name, socklen_t* namelen)
172 return getsockname(fd->GetFd(), name, namelen);
175 int SocketEngine::RecvFrom(EventHandler* fd, void *buf, size_t len, int flags, sockaddr *from, socklen_t *fromlen)
177 return recvfrom(fd->GetFd(), (char*)buf, len, flags, from, fromlen);
180 int SocketEngine::Send(EventHandler* fd, const void *buf, size_t len, int flags)
182 return send(fd->GetFd(), (const char*)buf, len, flags);
185 int SocketEngine::Recv(EventHandler* fd, void *buf, size_t len, int flags)
187 return recv(fd->GetFd(), (char*)buf, len, flags);
190 int SocketEngine::SendTo(EventHandler* fd, const void *buf, size_t len, int flags, const sockaddr *to, socklen_t tolen)
192 return sendto(fd->GetFd(), (const char*)buf, len, flags, to, tolen);
195 int SocketEngine::Connect(EventHandler* fd, const sockaddr *serv_addr, socklen_t addrlen)
197 return connect(fd->GetFd(), serv_addr, addrlen);
200 int SocketEngine::Shutdown(EventHandler* fd, int how)
202 return shutdown(fd->GetFd(), how);
205 int SocketEngine::Bind(int fd, const sockaddr *my_addr, socklen_t addrlen)
207 return bind(fd, my_addr, addrlen);
210 int SocketEngine::Listen(int sockfd, int backlog)
212 return listen(sockfd, backlog);
215 int SocketEngine::Shutdown(int fd, int how)
217 return shutdown(fd, how);
220 void SocketEngine::RecoverFromFork()